1、通过回调函数
Component({
/**
* 组件的方法列表
*/
methods: {
callSetNavTitle(callback) {
if (callback) {
callback();
}
},
setNavTitle () {
wx.setNavigationBarTitle({
title: '全部信息'
})
},
},
lifetimes: {
attached: function() {
this.callSetNavTitle(()=> this.setNavTitle())
},
},
});
2、通过bind改变this指向
Component({
/**
* 组件的方法列表
*/
methods: {
test(){
console.log('test')
}
},
lifetimes: {
this.test.bind(this)()
},
},
});
仅用于记录小程序开发中遇到的问题