想创建一个2d类型的canvas,采用微信官方文档中的范例,使用wx.createSelectorQuery().select(’#’).fields({ node: true, size: true }).exec()语句,可调试总是出错,显示Cannot read property ‘node’ of null;at SelectorQuery callback function。TypeError: Cannot read property ‘node’ of null。
index.wxml文件
<view class="head-container">
<canvas type="2d" canvas-id="canvasIdPass" style="width: 300px; height: 300px;"></canvas>
</view>
index.js文件
onLoad:function(){
wx.createSelectorQuery().select('#canvasIdPass').fields({ node: true, size: true }).exec(function(res){
const canvas = res[0].node
const ctx = canvas.getContext('2d')
console.log('res[0]', res[0])
})
}