lottie-player src路径错误>在Vue.js中不工作

发布时间 2023-07-27 15:47:45作者: wj704

lottie-player src路径错误>在Vue.js中不工作

浏览 153关注 0回答 1得票数 0
原文

当我在我的Vue.js代码中插入<lottie-player>并且动画来自lottiefiles的网站时:它工作得很好。但是如果我的animation.json来自我的公共文件,我会在控制台中得到这个错误:

Uncaught DOMException: Failed to read the ‘responseText’ property from ‘XMLHttpRequest’: The value is only accessible if the object’s ‘responseType’ is ‘’ or ‘text’ (was ‘json’).

我的代码如下所示:

<v-skeleton-loader width="100%" type="image">
  <lottie-player
    src="../public/image/animations/myanimation.json"
    background="transparent"
    style="width: 300px; height: 300px;" 
    speed="1"
    autoplay
  ></lottie-player>
</v-skeleton-loader>

不知道为什么。有人有解决方案吗?

1 个回答

Stack Overflow用户
回答于2021-10-08 11:05
得票数 0

最近我也遇到了同样的问题。

所以我切换到另一个npm包,在那里我也有类似的问题,但解决了它-在文档中,它指出您需要将json文件放在公共文件夹中。

公用文件夹通常是您的默认favicon和index.html文件所在的位置。因此,您可以先在此组件上尝试它,如下所示。

<lottie-player
    src="image/animations/myanimation.json"
    background="transparent"
    style="width: 300px; height: 300px;" 
    speed="1"
    autoplay
  ></lottie-player>

否则我会建议你看看https://www.npmjs.com/package/lottie-vuejs