创建'2d'canvas出现Cannot read 'node' of null的问题?
发布于 7 年前 作者 pgong 13850 次浏览 来自 官方Issues

想创建一个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])

})

}

3 回复

艾玛,我这白痴问题提的真有问题啊

感谢啊

库的版本还得在2.8.1以上,否则也是报null的错

回到顶部