How to use anime.js ( or any external library ) in a Vue-Cli project?

Mar*_*ube 2 webpack vue.js vue-cli anime.js

I installed Anime.js with npm as a dependencie to my project. Now i have a java script file "animate" where I have my anime code. How to link my component with my animate file to make the magic happen ? thanks for reading.

my animate.js file 我的 animate.js 文件

how I tried to link my animate file with my component 我如何尝试将我的动画文件与我的组件链接起来

acd*_*ior 5

Anime.js在 NPM 上可用。要与 vue-cli 一起使用,请先安装它:

npm install --save animejs
Run Code Online (Sandbox Code Playgroud)

在您的.js.vue文件中,导入anime函数:

npm install --save animejs
Run Code Online (Sandbox Code Playgroud)

在那之后,anime函数/对象将可以在该文件中使用。

例子:

使用import anime from 'animejs';(要获取对 DOM 元素的引用,可以使用refs)在您的组件中导入函数:

import anime from 'animejs';
Run Code Online (Sandbox Code Playgroud)

CodeSandbox 演示在这里