T
T
triplepointer2021-03-30 13:49:23
JavaScript
triplepointer, 2021-03-30 13:49:23

How to include jQuery and its plugins in a Vue app?

Jquery itself is easily imported via import in the component and used in the mounted lifecycle method. But when you import plugins via import, nothing works. When you try to put in html files with plugin scripts, which is located in the public folder, it says in the console: "Uncaught SyntaxError: Unexpected token '<'". Is there a way to include jquery plugins so that they can then be used in mounted?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vovash, 2021-03-30
@V0vash

import $ from “jQuery”;

window.$ = window.jQuery = $;

if(window.jQuery && window.$) { const somePlugin = import(“pathtoplugin”); }

Или 

if(window.jQuery && window.$) { const somePlugin = require(“pathtoplugin”); }

...
mounted: function(){
  $('#selector').somePlugin({
    // ... настройки плагина
  });
}
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question