wx.createSelectorQuery().select(`#${canvasId}`).fields({
node: true,
size: true,
}).exec(async (resList) => {
if (!resList.length) return;
const { node: canvas } = resList[0];
const ctx = canvas.getContext('2d')!;
console.log(ctx.canvas === canvas); // 返回 false,期望是 true
});
// 此处实现跟标准不同,所以封装自定义逻辑函数,需要同时传 ctx 和 canvas...
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-canvas
The
canvas
attribute must return the value it was initialized to when the object was created.