小程序自定义组件lifetime中如何调用methods?
发布于 5 年前 作者 mzhou 11513 次浏览 来自 官方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 回复

打个 console?

试试this.getBanners() ?
回到顶部