canvas定位出视图,不用hidden试下
报错canvasToTempFilePath: fail canvas is empty?<view class="story"> <canvas hidden="{{radarImg}}" canvas-id="canvas" type="2d" id="canvas" style="width: 100vw; height: calc(100vw / 750 * 1080);"></canvas> <image hidden="{{!radarImg}}" src="{{radarImg}}" style="width: 100vw; height: calc(100vw / 750 * 1080);" /> </view> openDialog: () => { console.log('openDialog()'); let ctx = wx.createCanvasContext('canvas'); // that.setData({ // radarImg: 'tempFilePath', // show: true // }); // console.log(that); ctx.draw(true, setTimeout(()=>{ wx.canvasToTempFilePath({ canvasId: 'canvas', success: function(res) { console.log(res); let tempFilePath = res.tempFilePath; that.setData({ radarImg: tempFilePath, show: true }); }, fail: function(res) { console.log(res); } }, that); },500)) }, that是在全局里定义的,在onload() 里 赋值 that = this;
2020-09-17