小程序有<canvas type="2d">,预览正常,调试闪退
发布于 7 年前 作者 cuixiulan 2717 次浏览 来自 问答

手机:Redmi K30i 5G


<!--index.wxml-->
<view class="container">
    <text class="user-motto">{{motto}}</text>
    <canvas class="test-canvas" canvas-id="test-canvas" width="750" height="750"></canvas>
    <canvas class="test-canvas-2d" type="2d" width="750" height="750"></canvas>
</view>

/**index.wxss**/
.test-canvas {
  width:100vw;
  height:100vw;
  background:#f0f0f0;
}

.test-canvas-2d {
  width:100vw;
  height:100vw;
  background:#fff0f0;
}
//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    motto: 'Hello World',
  },
  testOldCanvas(){
    const ctx=wx.createCanvasContext('test-canvas');
    ctx.fillStyle='rgba(0,0,0,0.3)';
    ctx.fillRect(10,10,350,350);
    ctx.drawImage('/images/earth.jpg',5,5,200,200);
    ctx.draw();
  },
  testNewCanvas(){
  },
  onReady: function () {
    this.testOldCanvas();
  }
})

https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html

1 回复

canvas 2d 不支持真机调试的

回到顶部