1. 組件嵌套, 在子組件中不能使用 canvas , 也不是說不能, 只能說使用了也沒用, H5 中顯示無果, 小程序一樣.
2. 在 H5 中 出現 canvas 閃爍的問題 , 就一定要用異步去顯示 canvas,
3. 繪制 canvas 時 得用 uniapp 中的 draw() 去繪制, 不然 不會顯示 (原生一般直接填充就完事了)
4. 一定要在 onReady 函數中進行實例化 canvas 並且繪制
代碼:
let ctx = uni.createCanvasContext('myCanvas', this);
中間省略了....................
- setTimeout(function() {
- // 必須延遲執行 不然 H5 不顯示
- ctx.stroke();
- ctx.draw() // 必須加上 uniapp 沒這兒玩意兒 顯示不出來不比原生 不加可以顯示
- }, 200)
來源: http://www.bubuko.com/infodetail-3496097.html