canvas组件怎么绘制不生效?
WXML:
<view>
<canvas type="2d" style="width: 400px; height: 400px;" canvas-id="canvasId"></canvas>
<button bindtap="draw">绘制</button>
</view>
JS:
const app = getApp()
Page({
data: {},
onLoad: function () {
},
draw(){
console.log(111)
const ctx = wx.createCanvasContext('canvasId')
ctx.rect(10, 10, 100, 30)
ctx.setStrokeStyle('yellow')
ctx.stroke()
ctx.draw()
}
})
代码执行了没有效果是什么情况?如下: