<canvas id="firstCanvas" type="2d"></canvas> wx.createSelectorQuery().select('#firstCanvas').fields({node:true,size:true}).exec((res) => { 这样写,还是报TypeError: Cannot read property 'node' of null。不知为啥?
创建'2d'canvas出现Cannot read 'node' of null的问题?想创建一个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]) }) }
2022-06-14