uniapp加载json动画

一、添加canvas画布

html 复制代码
<canvas id="lottie_demo" type="2d" style="display: inline-block;width: 148rpx; height: 148rpx;" />

二、引入依赖和JSON文件

安装依赖 npm install lottie-miniprogram --save

javascript 复制代码
import lottie from 'lottie-miniprogram';
import lottieJson from "@/static/json/aiIdentify.json"

三、使用lottie加载json动画

javascript 复制代码
    const state = reactive({
      that: getCurrentInstance(),
    })
javascript 复制代码
      uni.createSelectorQuery().in(state.that).select('#lottie_demo').node(res => {
        const canvas = res.node
        const context = canvas.getContext('2d')
        lottie.setup(canvas)
        lottie.loadAnimation({
          loop: true,
          autoplay: true,
          animationData: lottieJson,
          rendererSettings: {
            context,
          },
        })
      }).exec()

结果

相关推荐
frontend_frank1 天前
脱离 Electron autoUpdater:uni-app跨端更新:Windows+Android统一实现方案
android·前端·javascript·electron·uni-app
..过云雨1 天前
应用层自定义协议与序列化一站式指南
网络协议·tcp/ip·json·信息与通信
三天不学习1 天前
UniApp三端实时通信实战:SignalR在H5、APP、小程序的差异与实现
微信小程序·uni-app·signalr
念你那丝微笑1 天前
uView Plus + Vue3 + TypeScript + UniApp 正确引入 UnoCSS(避坑版)
vue.js·typescript·uni-app
eggcode1 天前
C#读写Bson格式的文件
c#·json·bson
念你那丝微笑1 天前
vue3+ts在uniapp项目中实现自动导入 ref 和 reactive
vue.js·typescript·uni-app
电商API&Tina1 天前
电商数据采集 API:驱动选品、定价、运营的数据分析核心引擎
大数据·开发语言·人工智能·python·数据分析·json
游戏开发爱好者81 天前
如何使用 AppUploader 提交上传 iOS 应用
android·ios·小程序·https·uni-app·iphone·webview
ID_180079054732 天前
闲鱼商品详情API接口基础架构解析
json
wtsolutions2 天前
Sheet-to-Doc数据格式支持:JSON/JSONL/CSV全解析
json