VillageTree.vue 828 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <canvas
  3. id="villageTree"
  4. :width="systemInfo.windowWidth"
  5. :height="200"
  6. />
  7. </template>
  8. <script setup>
  9. import { defineComponent, getCurrentInstance, onMounted } from 'vue';
  10. const instance = getCurrentInstance();
  11. const systemInfo = uni.getSystemInfoSync();
  12. let canvas = null;
  13. let ctx = null
  14. async function initCanvas() {
  15. uni.createSelectorQuery()
  16. .in(instance)
  17. .select('#villageTree')
  18. .fields({ node: true, size: true }, (res) => {
  19. const canvas = res[0].node
  20. const ctx = canvas.getContext('2d')
  21. // 保存到 this,方便其他函数使用
  22. canvas = canvas
  23. ctx = ctx
  24. })
  25. }
  26. function animate() {
  27. }
  28. function animate() {
  29. flag.rotation += 0.01
  30. requestAnimationFrame(() => animate(stage, flag))
  31. }
  32. onMounted(() => {
  33. initCanvas()
  34. });
  35. </script>