想在组件生命周期内调用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");
}
}
})
打个 console?
试试this.getBanners() ?