收藏
回答

TypeError: ctx.draw is not a function 是什么原因?

  wx.createSelectorQuery()

            .select('#myCanvas'// 在 WXML 中填入的 id

            .fields({

                node: true,

                size: true

            })

            .exec((res) => {

                // Canvas 对象

                const canvas = res[0].node

                // 渲染上下文

                const ctx = canvas.getContext('2d')


                // Canvas 画布的实际绘制宽高

                const width = res[0].width

                const height = res[0].height


                // 初始化画布大小

                const dpr = wx.getWindowInfo().pixelRatio

                canvas.width = width * dpr

                canvas.height = height * dpr

                ctx.scale(dpr, dpr)



                ctx.moveTo(10, 50)

                ctx.lineTo(100, 50)

                ctx.stroke()

                ctx.draw()


回答关注问题邀请回答
收藏
登录 后发表内容