收藏
回答

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

想在组件生命周期内调用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 个回答

  • 陈式坚
    陈式坚
    2020-02-27

    打个 console?

    试试this.getBanners() ?
    


    2020-02-27
    有用 2
    回复 1
    • SKY
      SKY
      2020-02-27
      去掉methods就解决了。。。谢谢
      2020-02-27
      回复
登录 后发表内容
问题标签