收藏
回答

canvas 2D 官方示例 真机调试 ?

 <!-- 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 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    2021-06-09

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

    2021-06-09
    有用
    回复 1
    • 康师傅
      康师傅
      2021-06-09
      为什么 ?  什么时候支持 ,
      2021-06-09
      回复
  • 风禾
    风禾
    2021-06-09

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

    2021-06-09
    有用
    回复 1
    • 康师傅
      康师傅
      2021-06-09
      对这个是官方的锅
      2021-06-09
      回复
登录 后发表内容