Bertho Joris
Bertho Joris

Reputation: 1601

How to include external js inside vue component

I want to make a slide image in my app using jQuery Slide Image I get from internet. This source must include external JS and CSS.

I just want to use this external library only for certain components, so I just want to import it in only one particular component (Home Component).

My app uses webpack as a module bundler. How do I import external js file? I have tried doing it inside <script> in Vue Components like

var slide = require('assets/template/js/jssor.slider-26.1.5.min.js');

But I got error :

Error: Cannot find module "assets/template/js/jssor.slider-26.1.5.min.js"

My application structure enter image description here

If the way I imported js files is wrong, how is the right way to use this js only on home component, without all components hit if i register in index.html

Upvotes: 3

Views: 19013

Answers (1)

riyaz-ali
riyaz-ali

Reputation: 9034

Module paths are resolved relative to the file being compiled. In this case, to import external script you need a path like:

var slide = require('../assets/template/js/jssor.slider-26.1.5.min.js');

Upvotes: 5

Related Questions