canvas, ios img.onload 不执行,开发者工具正常。
createCanvas () {
wx.createSelectorQuery()
.select('#myCanvas')
.fields({
node: true,
size: true,
})
.exec((res) => {
console.log(res)
this.initCanvas(res)
})
},
initCanvas(res) {
const that = this
const width = res[0].width
const height = res[0].height
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = width * dpr
canvas.height = height * dpr
ctx.scale(dpr, dpr)
var img = canvas.createImage()
img.src = 'https://mediabook.oss-cn-shanghai.aliyuncs.com/bangdivr/img/posterbg.jpg'
img.onload = (res) => {
console.log(res)
ctx.drawImage(img ,0, 0, 750, 1448, 0, 0, 750, 1448)
}
img.onerror = (err) => {
console.log(err)
}
},