vue.js - 类型错误 : Cannot read properties of undefined (reading 'length' ) when using vue-lottie

标签 vue.js lottie

我正在尝试通过使用 vue-lottie 使 Lottie 动画与 Vue 一起工作,我正在关注 the example code used in the repo ,但是当我尝试运行代码时,我在控制台中看到以下错误:

enter image description here

[Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'length')"

found in

---> <Lottie> at node_modules/vue-lottie/src/lottie.vue
       <VSheet>
         <TheThreeColumnLayOut> at src/components/TheThreeColumnLayout.vue
           <Dashboard> at src/views/Dashboard.vue
             <VMain>
               <VApp>
                 <App> at src/App.vue
                   <Root>

TypeError: Cannot read properties of undefined (reading 'length')
    at completeLayers (lottie.js?94f1:1579)
    at Object.completeData (lottie.js?94f1:1968)
    at workerStart (lottie.js?94f1:2071)
    at Object.postMessage (lottie.js?94f1:1545)
    at Object.completeAnimation (lottie.js?94f1:2147)
    at AnimationItem.setupAnimation (lottie.js?94f1:12992)
    at AnimationItem.setParams (lottie.js?94f1:12970)
    at Object.loadAnimation (lottie.js?94f1:12711)
    at Object.loadAnimation (lottie.js?94f1:16474)
    at VueComponent.mounted (lottie.vue?d421:30)

最佳答案

经过大量谷歌搜索后,我找到了描述 here 的解决方案:

解决方法:

而不是像这样导入动画数据(如示例所示):

import * as animationData from '../path/to/the/animationData.json'

...而是像这样导入它:

从“../path/to/the/animationData.json”导入动画数据


因此,在您自己的代码中使用 vue-lottie 的最小工作示例如下所示:

<template>
  <div>
    <Lottie :options="animationOptions" />
  </div>
</template>

<script>
import Lottie from 'vue-lottie/src/lottie.vue'
import animationData from '../path/to/your/animation.json'
export default {
  components: {
    Lottie
  },
  data: function () {
    return {
      animationOptions: {
        animationData: animationData
      }
    }
  }
}
</script>

关于vue.js - 类型错误 : Cannot read properties of undefined (reading 'length' ) when using vue-lottie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69953082/

相关文章:

vue.js - 在 'default' 中找不到导出 'vue'(作为 Vue 导入)

vue.js - Vue-i18n - npm run serve 失败,错误为 TypeError : Cannot read property 'i18n' of undefined

ios - UIStackView 中的 Lottie AnimationView 大小不明确

ios - Lottie:无法获取带名称的动画

vue.js - 具有函数的表格过滤器

javascript - 如何在 Vue Js 中进行选择性悬停?

javascript - Vue.js Axios : How to call method from an HTML component passing an argument

javascript - 如何在 componentWillReceiveProps 上运行 Lottie 动画?

android - Lottie 动画库 Z 排序问题

Flutter Web : Lottie Animation is cropped on Android Chrome, 但 Windows Chrome 没问题