调用页面内方法如何弄呀?

发布于 6 年前作者 lixie12860 次浏览最后编辑 6 年前来自 ask

app.js

App({

    check(that,func){

        that.func()

    }

})

Page.js

var app = getApp()

Page({

    test(){

        console.log(‘test’)

    }

    onLoad(){

        var that = this

        app.check(that,‘test’)

    }

})

app.js如何写如何调用test呀,大神指教

5 回复
taoguiying
taoguiying1 楼6 年前

按照你的写法

App({

    check(that,func){

        that && typeof that[func] == 'function' && that[func]()

    }

})

jun51
jun512 楼6 年前

你这是什么需求?

shaoping
shaoping3 楼6 年前

app调用test?  app先加载的,page页面后加载,app怎么能调用还没有加载的函数呢?你这是什么需求?

xiaye
xiaye4 楼6 年前

App({

    check(func){

        func()

    }

})

var app = getApp()

Page({

    test(){

        console.log('test')

    }

    onLoad(){

        app.check(this.test)

    }

})




xlin
xlin5 楼4 年前

楼上正解