想要用小程序画带自定义二维码的海报,从官网弄的实例粘贴过来之后报错
VM2377 WAService.js:2 TypeError: Cannot read property 'node' of null
官网实例在这里
canvas | 微信开放文档
微信开发者平台文档
https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html
官网实例照抄了一下,本来想试试的,结果报错了了,我加了一行console.log(res),显示为null,求指点
<canvas type="2d" id="myCanvas"></canvas>
```javascript
Page({
onReady() {
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
//console.log(res)
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 100, 100)
})
}
})
```