收藏
回答

canvas 获取失败?

export default class ProgressPanel extends Component {
  
    componentDidMount () {
        console.log('test componentDidMount')
        const query = wx.createSelectorQuery().in(this)
        query.select('#myCanvas')
          .fields({ node: true, size: true })
          .exec((res) => {
            console.log('test ProgressPanel res 没执行到这里', 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)
          })
    }
 
 
    public render() {
        return (
            <View className="panel">
                <View className="panel-background">
                    <View id="canvas_container" className="panel-background-gray">
                        <canvas style='width: 300px; height: 200px;' canvas-id='myCanvas' />
                    </View>
 
                </View>
 
            </View>
        )
 
    }
     
}

获取失败 没有拿到canvas

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

2 个回答

登录 后发表内容
问题标签