topWindow页面代码:
<canvas canvas-id="test_canvas" style="background-color: #ff0;width:100px;height:50px;"></canvas>
js代码
mounted() {
setTimeout(() => {
let ctx = uni.createCanvasContext('test_canvas');
ctx.setFillStyle('red');
ctx.fillRect(0, 0, 20, 20);
ctx.restore();
ctx.draw(false,()=>{
console.log('topWindow绘画成功');
});
}, 1000);
},
page-index的页面代码:
<canvas canvas-id="test_page_canvas" style="background-color: #ff0;width:100px;height:50px;"></canvas>
js代码
onReady() {
setTimeout(() => {
let ctx = uni.createCanvasContext('test_page_canvas');
ctx.setFillStyle('red');
ctx.fillRect(0, 0, 20, 20);
ctx.restore();
ctx.draw(false,()=>{
console.log('Page绘画成功');
});
}, 1000);
},