1.lottie的安装
npm install lottie-web --save
2.创建一个子组件,用来封装lottie动画
<template>
<!-- 为容器绑定样式 -->
<div :style="style" ref="lavContainer"></div>
</template>
<script>
//引入lottie
import lottie from 'lottie-web'
//引入json数据
import machinery from '../../../public/dgz/data.json'
export default {
props: { //接收父元素传入的参数
options: {
type: Object,
required: true
},
height: Number,
width: Number
},
data() {
return {
style: { //设置容器的样式
// width: this.width ? `${this.width}px` : '40%', //如果父元素有传参则使用传参的值,没有则=40%
// height: this.height ? `${this.height}px` : '100%',//如果父元素有传参则使用传参的值,没有则=100%
overflow: 'hidden',//超出