sign1ok: function () { var that = this; if(!that.data.hasDraw){ wx.showToast({ title: '签字是空白的 请签名', icon:'none' }) }else{ var context1 = that.data.context1; context1.draw(true, wx.canvasToTempFilePath({ canvasId: 'handWriting1', success(res) { console.log(this.data.customerTaskId) wx.redirectTo({ url: '/pages/task/rectifyFeedback/rectifyFeedback?imagefile='+res.tempFilePath + '&customerTaskId=' + this.data.customerTaskId, }) // console.log(res.tempFilePath) } }) ) } },这样写代码为什么会报错“Cannot read property 'customerTaskId' of undefined”
时间: 2023-11-22 13:52:45 浏览: 139
这个错误是因为在`wx.redirectTo()`中,`this`的值为`undefined`。你可以尝试将`this`的值保存到一个变量中,然后在`wx.redirectTo()`中使用该变量。
例如:
```
sign1ok: function () {
var that = this;
if(!that.data.hasDraw){
wx.showToast({
title: '签字是空白的 请签名',
icon:'none'
})
} else {
var context1 = that.data.context1;
context1.draw(true, wx.canvasToTempFilePath({
canvasId: 'handWriting1',
success(res) {
console.log(that.data.customerTaskId)
wx.redirectTo({
url: '/pages/task/rectifyFeedback/rectifyFeedback?imagefile='+res.tempFilePath + '&customerTaskId=' + that.data.customerTaskId,
})
// console.log(res.tempFilePath)
}
})
}
},
```
这样就可以避免这个错误了。
阅读全文