index.vue 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <lottie-animation :options="defaultOptions" v-on:animCreated="handleAnimation" />
  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. key: +new Date()
  13. };
  14. },
  15. created() {
  16. if (this.data.default) {
  17. this.data.default.assets.forEach((item) => {
  18. item.u = '';
  19. if (item.w && item.h) {
  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. handleAnimation(anim) {
  36. console.log(anim)
  37. }
  38. }
  39. };
  40. </script>
  41. <style></style>