把图片导入2d画布出现问题?
const app = getApp()
Page({
data: {},
onLoad: function () {
// 通过 SelectorQuery 获取 Canvas 节点
wx.createSelectorQuery()
.select('#canvas')
.fields({
node: true,
size: true,
})
.exec(this.init.bind(this))
},
init(res) {
const ctx = canvas.getContext('2d')
this.drawCar(ctx)
const img = canvas.createImage()
img.onload = () => {
this._img = img
}
img.src = './car.png'
},
drawCar(ctx) {
ctx.drawImage(this._img, 0, 0, 100, 50)
ctx.restore()
}
})