wx.createSelectorQuery() 真机无法调用回调
< canvas type = "webgl" id = "c" ></ canvas > |
wx.createSelectorQuery() .select( '#c' ) .node() .exec((res) => { let canvasId = res[0].node._canvasId console.log(canvasId) }) |
在工具中,这个api回调可以正常,但是到真机上则无法正常执行
4 回复
我也遇到相同问题
wxml
<canvas id="rafCanvas" type="2d" style="display:none;"></canvas>
ts
onLoad(options) {
const eventChannel = this.getOpenerEventChannel();
// 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
eventChannel.on('acceptDataFromOpenerPage', (data: { path: string; size: number }) => {
// 通过 SelectorQuery 获取 Canvas 节点
wx.createSelectorQuery()
.select('#rafCanvas')
.fields({
node: true,
})
.exec(res => {
canvas = res[0].node;
wx.getSystemInfo({
success: res => {
this.setData({
windowHeight: res.windowHeight,
windowWidth: res.windowWidth,
pixelRatio: res.pixelRatio,
});
this.analysis(data);
},
fail: err => {
console.log(err);
},
});
});
});
},