<view class="uni-container">
<canvas id="customMapId2" type="2d">
</canvas>
</view>
onReady() {
debugger
const query = wx.createSelectorQuery().in(this)
query.select('customMapId2').fields({ node: true, rect: true }).exec((res) => {
debugger
console.error("123")
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)
})
},
其中select部分带#走不到回调里面,不带#后可以走到回调,但是res.length=1,res[0]=null,获取不到canvas的node
题主解决没,我测试发现canvas采用新api type='2d' 是可以获取到node的。但是旧的canvas api无法获取node