You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue.js报错:Unexpected token < in JSON at position 0 求解

修复Lottie-Web配置参数的错误

嘿,我一眼就发现问题所在啦!你在animationParams里把loop和autoplay设置成了字符串类型的'true'和'false',但Lottie-Web的这两个配置项需要的是布尔值(不带引号的true/false),这就是导致错误的核心原因。

修复后的代码

import Lottie from './../../node_modules/lottie-web/build/player/lottie';
export default {
  name: 'Illustration',
  mounted() {
    this.animationParams = {
      container: document.getElementById('animation'),
      renderer: 'svg',
      loop: true, // 去掉引号,使用布尔值
      autoplay: false, // 去掉引号,使用布尔值
      path: '/sr...' // 确保这里是正确的Lottie动画JSON文件路径
    }
    // 别忘了添加动画初始化代码哦!
    Lottie.loadAnimation(this.animationParams);
  }
}

额外小提醒

  • 确认container对应的DOM元素(id为animation的元素)在组件挂载时已经存在,不然document.getElementById会返回null
  • 保证path指向的是正确的Lottie动画JSON文件路径,路径错误也会导致动画无法加载

内容的提问来源于stack exchange,提问作者Carlos Pisarello

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:56:19