npm install lottie-web
<template>
<div class="index">
<div class="zan"></div>
</div>
</template>
<script setup name="index">
import { onMounted, nextTick } from "vue";
import dataJson from "../assets/data.json";
import lottie from "lottie-web";
onMounted(() => {
nextTick(() => {
jsonAnimation(document.getElementsByClassName("zan")[0], dataJson);
});
});
const jsonAnimation = (dom, jsonFile) => {
lottie.loadAnimation({
container: dom,
renderer: "svg",
loop: true,
autoplay: true,
animationData: jsonFile,
});
};
</script>
<style scoped lang="less">
.index {
width: 100vw;
height: 100vh;
background: skyblue;
.zan {
width: 200px;
height: 200px;
}
}
</style>