收藏
回答

canvas使用真机测试报错Z.createEvent is not a function?

开发者工具调试没问题可正常运行,真机调试直接报错如下

代码如下

 onLoad: function (options{
    wx.createSelectorQuery()
      .select('#mycanvas')
      .fields({
        node: true,
        size: true
      }, (res) => {
        console.log(res)
        const canvas = res.node
        const ctx = canvas.getContext('2d');


        this.init(ctx, canvas)
      })
      .exec()
  },



  init(ctx, canvas) {


    let img = canvas.createImage()
    img.onload = (e) => {
      console.log(img.width, img.height)
      let c_x = img.width * 0.05
      let c_w = img.width * 0.89
      let c_y = img.height * 0.365
      let c_h = img.height * 0.12
      console.log(c_x, c_y, c_w, c_h)
      ctx.drawImage(img, c_x, c_y, c_w, c_h, 00, c_w, c_h)
    }
    img.onerror = (e) => {
      console.error('err:', e)
    }
    img.src = 'https://img1.baidu.com/it/u=1762106751,3246977936&fm=26&fmt=auto&gp=0.jpg'
},



  请问应该怎么解决

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容