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)
}
},