callback 回调不准确
likaixuan opened this issue · 8 comments
likaixuan commented
Description
我需要通过 wx.canvasToTempFilePath 获取画布的临时路径、但它必须是draw 绘制完成之后才能获取 我无法通过callback来完成这个操作(在安卓机型上它比draw要快)、目前只能通过callback加定时器延时来解决
yingye commented
@likaixuan 贴一下代码吧~
tinyzh commented
我在安卓机上也遇到,也是只能在callback里面用setTimeout来进行下一步操作
savokiss commented
暂时只能加延时了
return new Promise((resolve, reject) => {
drawQrcode({
width: 200,
height: 200,
canvasId: 'qrcode',
text: url,
_this: this,
callback: () => {
// 安卓机上不准确,生成的二维码无法扫描,加延时解决
setTimeout(() => {
wx.canvasToTempFilePath({
canvasId: 'qrcode',
success: res => {
resolve(res)
}
}, this)
}, 500)
}
})
})
sai2333 commented
在红米7机型上使用延迟,还是没有没办法获取完整。目前还只是在红米七,不知道其它的机型怎么样,我自己的红米note5没问题- -
zwmmm commented
iOS 放在callback里面反而获取不到临时路径了,无语了
ZhangDaZongWei commented
` const imgPath = new Promise((resolve, reject) => {
drawQrcode({
width: 200*scale,
height: 200*scale,
canvasId: 'myQrcode',
_this: this.$scope,
text: 'https://www.baidu.com',
background: 'tomato',
foreground: '#ffffff',
callback: () => {
setTimeout(() => {
Taro.canvasToTempFilePath({
canvasId: 'myQrcode',
success: res => {
resolve(res)
}
})
},500)
}
})
})
imgPath.then(res => console.log('res: ', res))
}`
我使用了Taro框架,为啥不会打印res呢?
ZhangDaZongWei commented
` const imgPath = new Promise((resolve, reject) => {
drawQrcode({ width: 200*scale, height: 200*scale, canvasId: 'myQrcode', _this: this.$scope, text: 'https://www.baidu.com', background: 'tomato', foreground: '#ffffff', callback: () => { setTimeout(() => { Taro.canvasToTempFilePath({ canvasId: 'myQrcode', success: res => { resolve(res) } }) },500) } }) }) imgPath.then(res => console.log('res: ', res))
}`
我使用了Taro框架,为啥不会打印res呢?
canvasToFilePath还有第二个参数,加上this.$scope即可