找不到相关模块:vue-lottie

问题描述 投票:0回答:2

在使用vue-cli(3.0.0-rc.5)进行全新构建之后,无法到达lottie模块的路径。我应该玩配置吗?


  • ./lottie.vue in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!。/ node_modules / cache-download / did / cjs。 JS ?? REF - !?0-0 ./ node_modules / VUE装载机/ lib目录?? VUE装载机选项./ SRC /组件/ HelloWorld.vue VUE&类型=脚本&LANG = JS&

<template>
<div id="app">
    <lottie :options="defaultOptions" :height="400" :width="400" v-on:animCreated="handleAnimation"/>
    <div>
        <p>Speed: x{{animationSpeed}}</p>
        <input type="range" value="1" min="0" max="3" step="0.5"
               v-on:change="onSpeedChange" v-model="animationSpeed">
    </div>
    <button v-on:click="stop">stop</button>
    <button v-on:click="pause">pause</button>
    <button v-on:click="play">play</button>
</div>

<script>
      import Lottie from './lottie.vue';
      import * as animationData from './assets/data.json';
      export default {
        name: 'app',
        components: {
          'lottie': Lottie
        },
        data() {
          return {
            defaultOptions: {animationData: animationData},
            animationSpeed: 1
          }
        },
        methods: {
          handleAnimation: function (anim) {
            this.anim = anim;
          },
          stop: function () {
            this.anim.stop();
          },
          play: function () {
            this.anim.play();
          },
          pause: function () {
            this.anim.pause();
          },
          onSpeedChange: function () {
            this.anim.setSpeed(this.animationSpeed);
          }
        }
      }
    </script>
vue.js npm vue-cli-3
2个回答
1
投票

如果你使用vue-lottie包,那么导入应该是

import Lottie from 'vue-lottie';

这是因为lottie包位于node_modules文件夹中,您必须提供正确的路径或使用直接包名称导入。另外,我相信当前版本的Vue cli是v3.1.1所以你一定要升级。


0
投票

如果仍然无效,请在defaultOptions中将animationData更改为animationData.default

defaultOptions: { animationData: animationData.default }
© www.soinside.com 2019 - 2024. All rights reserved.