var barcodeModel = uni.requireNativePlugin("iData-BarcodePlugin-BarcodeModule")
var modal = uni.requireNativePlugin('modal');
var globalEvent = uni.requireNativePlugin('globalEvent');
export default {
onLoad() {
globalEvent.addEventListener('iDataBarcodeEvent', function(e) {
modal.toast({
message: "收到条码:" + JSON.stringify(e),
duration: 1.5
});
});
this.code(e)
},
methods: {
code(e) {
console.log(e);
}
}
}
页面监听event事件无法调用methods的方法,求解
2 个回复
y***@loongair.cn
用that替换this
onLoad() {
let that = this
globalEvent.addEventListener('iDataBarcodeEvent', function(e) {
modal.toast({
message: "收到条码:" + JSON.stringify(e),
duration: 1.5
});
});
that.code(e)
},
falost
把 function(e) 改成箭头函数 this 才生效