index.vue 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <lottie-animation :options="defaultOptions" />
  3. </template>
  4. <script>
  5. import LottieAnimation from 'vue-lottie';
  6. export default {
  7. props: ['data'],
  8. name: 'lottie',
  9. data() {
  10. return {
  11. defaultOptions: {},
  12. };
  13. },
  14. created() {
  15. if (this.data?.default) {
  16. this.data?.default.assets.forEach((item) => {
  17. item.u = '';
  18. if (item.w && item.h) {
  19. if(item.p.includes('assets/lottie/images')) return
  20. item.p = require(`@/assets/lottie/images/${item.p}`);
  21. }
  22. });
  23. this.defaultOptions = {
  24. animationData: this.data?.default,
  25. renderer: 'svg', //渲染方式,svg、canvas、html(轻量版仅svg渲染)
  26. loop: true, //是否循环播放,true表示循环,false表示不循环
  27. autoplay: true, //是否自动播放,true表示自动播放
  28. };
  29. }
  30. },
  31. components: {
  32. LottieAnimation,
  33. },
  34. methods: {
  35. }
  36. };
  37. </script>
  38. <style></style>