剪头函数:
OnfinishTakeOnePic:(filepath)=>{
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('takeOnePictureFinished', {
filepath: filepath
});
wx.navigateBack();
}
//传统写法:
OnfinishTakeOnePic:function(filepath){
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('takeOnePictureFinished', {
filepath: filepath
});
wx.navigateBack();
}
剪头函数写法this指针为undefined,啥情况??
箭头函数你用this指向会指向上一层,然而你上一层没东西,所以你要用箭头函数,只能在函数里面用
在onLoad
或
this.ctx.takePhoto的success回调函数中调用都不行
this不是传过去的,OnfinishTakeOnePic本身是page的函数: Page({ /** * 页面的初始数据 */ data: {}, onLoad: function (options) { ...... }, OnfinishTakeOnePic:function(filepath){
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('takeOnePictureFinished', {
filepath: filepath
});
wx.navigateBack();
}
})
哪里调用给他传个参数this
onshow:function(){
this.OnfinishTakeOnePic(this,OnfinishTakeOnePic);
}