1、安装lottie-web插件
npm install lottie-web
2、使用
1、下载动画:在lottiefiles网站可以下载
https://lottiefiles.com/featured
2、将下载的动画放在assets的json文件夹下
3、在需要使用的页面使用:如下
<div ref="bodyAnimation"></div>
import lottie from "lottie-web";
import animationJson from "@/assets/json/animation.json";
mounted() {
lottie.loadAnimation({
container: this.$refs.bodyAnimation,
renderer: "svg",
loop: true,
autoplay: true,
animationData: animationJson,
});
},
3、下面这个方法已失效(会报错原因未发现)
mounted() {
const animData = {
wrapper: document.getElementById("bodymovin"),
animType: "html",
loop: true,
prerender: true,
autoplay: true,
path: "/static/js/loginDonfTu/data.json"
};
bodymovin.loadAnimation(animData);
},
<script src="/static/js/lottie.min.js"></script>
此处可以下载插件