最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to include external js inside vue component - Stack Overflow

programmeradmin1浏览0评论

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 ponents, so I just want to import it in only one particular ponent (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

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

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 ponents, so I just want to import it in only one particular ponent (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

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

Share edited Sep 4, 2017 at 14:33 riyaz-ali 9,1022 gold badges25 silver badges38 bronze badges asked Sep 4, 2017 at 14:25 Bertho JorisBertho Joris 1,6015 gold badges28 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Module paths are resolved relative to the file being piled. 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');
发布评论

评论列表(0)

  1. 暂无评论