小程序自定义组件lifetime中如何调用methods?

发布于 7 年前作者 mzhou11785 次浏览最后编辑 7 年前来自 issues

想在组件生命周期内调用methods,但是提示错误:

VM1461:1 thirdScriptError

Cannot read property ‘getBanners’ of undefined; [Component] Lifetime Method Error @ utils/components/banner/banner#attached

TypeError: Cannot read property ‘getBanners’ of undefined

下面是代码:

Component({
lifetimes: {

    attached: function () {
    this.methods.getBanners();
    },

},

pageLifetimes: {

    show: function () {
 
    },
},
properties: {
},

/**
* Component initial data
*/
data: {
},

/**
* Component methods
*/
methods: {
    getBanners: function() {
    
      console.log("getting banners");
    }

}
})
1 回复
li84
li841 楼5 年前

打个 console?

试试this.getBanners() ?