怎么在自定义组件中使用canvas2d呢 ?一直报错node为空
发布于 6 年前 作者 yejuan 10822 次浏览 来自 问答
Ready() {
    const query = this.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)
      })
1 回复

谢邀:

你wxml里有id为'myCanvas'的canvas组件了吗?设置type为2d了吗
回到顶部