canvas-child.uvue 882 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <view>
  3. <canvas id="canvas1"></canvas>
  4. </view>
  5. <view>
  6. <canvas id="canvas2"></canvas>
  7. </view>
  8. <view>
  9. {{testCounter}}
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. // 仅测试
  17. testCounter: 0,
  18. }
  19. },
  20. mounted() {
  21. uni.createCanvasContextAsync({
  22. id: 'canvas1',
  23. component: this,
  24. success: (_ : CanvasContext) => {
  25. this.testCounter++
  26. this._dispatchEvent()
  27. }
  28. });
  29. uni.createCanvasContextAsync({
  30. id: 'canvas2',
  31. component: this,
  32. success: (_ : CanvasContext) => {
  33. this.testCounter++
  34. this._dispatchEvent()
  35. }
  36. });
  37. },
  38. methods: {
  39. _dispatchEvent() {
  40. if (this.testCounter == 2) {
  41. uni.$emit('canvasChildReady')
  42. }
  43. }
  44. }
  45. }
  46. </script>