Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import anime.js to my Vue project?

I have a question regarding importing an anime.js into my vue project. I am using vue cli. How do I include animejs to my project? I tried it this way:

import anime from 'animejs'
Vue.use(anime);

but I get an error in the console that says:

Uncaught TypeError: a.hasOwnProperty is not a function. . .

can you guys help me?

like image 433
Brayn Brigoli Avatar asked Jan 29 '23 12:01

Brayn Brigoli


2 Answers

Vue.use() is used only for plugins designed for Vue.js. You can't simply add a library there, it won't work.

My suggestion is that you create that plugin and use it on your project to make anime.js acessible everywhere.

You could do it like this:

//vue-anime.js
import anime from 'animejs';

const VueAnime = {
  install (Vue, options) {
    Vue.prototype.$animeJS = anime;
  }
}

export default VueAnime

Then later

import VueAnime from './vue-anime';
Vue.use(VueAnime);

Now every Vue component will be able to use anime acessing this.$animeJS.

like image 86
Phiter Avatar answered Jan 31 '23 01:01

Phiter


Or simply -

import Vue from "vue";
import anime from 'animejs/lib/anime.min.js';

Vue.prototype.$anime = anime;

Then this.$anime in all components

like image 20
Spotd Avatar answered Jan 31 '23 02:01

Spotd