<!-- canvas.wxml -->
<canvas type="2d" id="myCanvas"></canvas>
// canvas.js
Page({
onReady() {
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
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)
ctx.fillRect(0, 0, 100, 100)
})
}
})
VM13:2 MiniProgramError
U.createEvent is not a function
TypeError: U.createEvent is not a function
at Q (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:30303)
at eval (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:30601)
at e.exports (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:35763)
at eval (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:30552)
at y.<computed> (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:33829)
at O (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:33558)
at Function.eval (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:33596)
at <setTimeout callback function>
at eval (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:110340)
at eval (eval at n.call.document (http://127.0.0.1:42506/remote-debug/runtime.js?devtools_ignore=true:1:13107), <anonymous>:2:101485)