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()

结果

相关推荐
宠友信息2 小时前
多端即时通讯源码技术实践,Redis路由、MySQL持久化与Socket接入
spring boot·websocket·mysql·uni-app
SelectDB技术团队4 小时前
Agent 场景动态 JSON 性能拆解:Apache Doris 比 ClickHouse 快 7 倍、比 Elasticsearch 快 2 倍
数据库·clickhouse·elasticsearch·json·apache·日志分析·apache doris
宠友信息5 小时前
Spring Boot与异步审核构建仿小红书源码内容发布全流程
java·数据库·spring boot·redis·mysql·oracle·uni-app
蜡台5 小时前
uniapp vue2 转 vue3
前端·javascript·uni-app·vue3·vue2
2501_916008897 小时前
iOS 证书管理最佳实践 从创建到续期的完整指南
android·ios·小程序·https·uni-app·iphone·webview
Amy187021118231 天前
UL证书只是起点——智能电表出口北美,真正的考验在量产之后
json
SelectDB1 天前
Agent 场景动态 JSON 性能拆解:Apache Doris 比 ClickHouse 快 7 倍、比 Elasticsearch 快 2 倍
数据库·json·agent
敖行客 Allthinker1 天前
UniApp iOS APNs 推送证书一站式配置
uni-app·mac
梦曦i1 天前
uni-router新推useUniEventChannel,彻底解决页面通信难题
前端·uni-app
宠友信息1 天前
内容社区源码多端数据协议与 Spring Boot 状态流转实现思路
java·spring boot·websocket·uni-app