看你描述是在当前页面画海报没问题,就是去别的页面后返回就会报这个错。我也是相同的问题,进去后直接画没有问题,退出去后再进来就报错了。
canvas 2d 报错 toTempFilePath:fail invalid viewid?模拟器没问题,真机一直报 toTempFilePath:fail invalid viewid? 业务是当前页面 需要点击进入别的页面填写内容,然后带参数返回 然后画海报保存 当前页面画直接画海报没问题,返回一直报 toTempFilePath:fail invalid viewid? onReady() { this.drawImage() }, drawImage: function () { let that = this const query = wx.createSelectorQuery() query.select('#myCanvas') .fields({ node: true, size: true }) .exec((res) => { const canvas = res[0].node const canvasRes = res[0] const ctx = canvas.getContext('2d') const dpr = wx.getSystemInfoSync().pixelRatio that.setData({ canvas , canvasRes, ctx, dpr }) }) }, drawImageDetail() { try { let userInfo = this.data.userInfo let canvasRes = this.data.canvasRes let canvas = this.data.canvas let dpr = this.data.dpr let ctx = this.data.ctx let that = this canvas.width = canvasRes.width * dpr canvas.height = canvasRes.height * dpr ctx.scale(dpr, dpr) ctx.fillStyle = 'white' ctx.fillRect(0, 0, canvas.width, canvas.height) ctx.font = '14px DINCondensed-Bold' ctx.fillStyle = '#BEC5CC' ctx.fillText(`生成海报`, 0, 0); setTimeout(() => { wx.canvasToTempFilePath({ canvas: canvas, success(res) { console.log(res.tempFilePath) }, fail(res){ console.log(res) } }) }, 400) } catch (error) { console.log(error) } },
2022-08-02请问你解决了么,我是第一次进去正常,第二次就报错
canvasToTempFilePath:fail invalid viewIdhttps://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html [图片] 手机型号:iPhoneX 运行系统:IOS 15.4.1 微信版本:8.0.25 基础库版本:2.25.1 代码如下: ctx.draw(false, (() => { setTimeout( () => { wx.canvasToTempFilePath({ quality: 0.5, fileType: 'jpg', canvasId: 'firstCanvas', success: function (res) { wx.hideLoading() that.setData({ 'markPhoto': res.tempFilePath }) }, fail: function(error) { console.log('error', error) }, complete (complete) { console.log('complete', complete) } }, that) }, 100) })())
2022-08-02