开发者工具调试没问题可正常运行,真机调试直接报错如下
代码如下
onLoad: function (options) {
wx.createSelectorQuery()
.select('#mycanvas')
.fields({
node: true,
size: true
}, (res) => {
console.log(res)
const canvas = res.node
const ctx = canvas.getContext('2d');
this.init(ctx, canvas)
})
.exec()
},
init(ctx, canvas) {
let img = canvas.createImage()
img.onload = (e) => {
console.log(img.width, img.height)
let c_x = img.width * 0.05
let c_w = img.width * 0.89
let c_y = img.height * 0.365
let c_h = img.height * 0.12
console.log(c_x, c_y, c_w, c_h)
ctx.drawImage(img, c_x, c_y, c_w, c_h, 0, 0, c_w, c_h)
}
img.onerror = (e) => {
console.error('err:', e)
}
img.src = 'https://img1.baidu.com/it/u=1762106751,3246977936&fm=26&fmt=auto&gp=0.jpg'
},
请问应该怎么解决
试试真机调试2.0