E
E
Enfiladed2019-10-07 00:53:34
Vue.js
Enfiladed, 2019-10-07 00:53:34

How to include third party library in vue/cli project?

Hello! I know this has been asked before, but I couldn't find a good answer anywhere. There is a small autosize library that takes a texarea and controls its size. Autosize is in the assets folder. The project structure is standard:
-public
-src
--assets
--components
--main.js
--app.vue
What I do:

import autosize from "../assets/autosize-master/dist/autosize.js"

...
mounted: function(){
         autosize(this.$refs.textarea)
  }
...

It seems like it should work, ES6 is all the same, but no.
Connecting in index.html doesn't work either btw. Is there some more or less simple way so that you don’t have to create plugins for example? Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2019-10-07
@Lisey

npm i autosize
In the required component:

import autosize from 'autosize';

mounted() {
    autosize(this.$refs.someEl);
}

That is, you did everything correctly, but apparently something is wrong with the paths or something else.
Regarding plugins and wrapper components, there is a section in the documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question