Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback 回调不准确 #18

Open
likaixuan opened this issue Oct 18, 2018 · 8 comments
Open

callback 回调不准确 #18

likaixuan opened this issue Oct 18, 2018 · 8 comments

Comments

@likaixuan
Copy link

Description

我需要通过 wx.canvasToTempFilePath 获取画布的临时路径、但它必须是draw 绘制完成之后才能获取 我无法通过callback来完成这个操作(在安卓机型上它比draw要快)、目前只能通过callback加定时器延时来解决

@yingye
Copy link
Owner

yingye commented Oct 18, 2018

@likaixuan 贴一下代码吧~

@tinyzh
Copy link

tinyzh commented Dec 4, 2018

我在安卓机上也遇到,也是只能在callback里面用setTimeout来进行下一步操作

@savokiss
Copy link

暂时只能加延时了

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
Copy link

sai2333 commented Aug 5, 2019

在红米7机型上使用延迟,还是没有没办法获取完整。目前还只是在红米七,不知道其它的机型怎么样,我自己的红米note5没问题- -

@likaixuan
Copy link
Author

@sai2333 加大延迟呢

@zwmmm
Copy link

zwmmm commented Sep 2, 2019

iOS 放在callback里面反而获取不到临时路径了,无语了

@ZhangDaZongWei
Copy link

` 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
Copy link

` 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即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants