index.vue 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.ww) item.ww = item.p
  20. if(item.p.includes('assets/lottie/images')) return
  21. item.p = require(`@/assets/lottie/images/${item.ww}`);
  22. }
  23. });
  24. this.defaultOptions = {
  25. animationData: this.data?.default,
  26. renderer: 'svg', //渲染方式,svg、canvas、html(轻量版仅svg渲染)
  27. loop: true, //是否循环播放,true表示循环,false表示不循环
  28. autoplay: true, //是否自动播放,true表示自动播放
  29. };
  30. }
  31. },
  32. components: {
  33. LottieAnimation,
  34. },
  35. methods: {
  36. }
  37. };
  38. </script>
  39. <style></style>