canvas 2D 官方示例 真机调试 ?
发布于 5 年前 作者 dongli 7356 次浏览 来自 官方Issues
 <!-- 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)

2 回复

你好,canvas 2d 暂不支持真机调试,请直接使用真机预览。

你搜一下,社区里遇到这个问题的人很多

回到顶部