Home  >  Q&A  >  body text

javascript - How vue components introduce external js

I want to introduce an external swiper.js into a single-page component. I don’t want to install dependencies. I want to import js directly. Is there a way to achieve this? I have tried both import and require but it seems to have failed.

伊谢尔伦伊谢尔伦2692 days ago670

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-06-05 11:14:49

    Just import it directly under index.html through <script>

    reply
    0
  • 阿神

    阿神2017-06-05 11:14:49

    Introduce the js file you need to load in the index.html page

    reply
    0
  • 迷茫

    迷茫2017-06-05 11:14:49

    require / exports is CommonJS (implemented in Node), import / export is a module of ES2015, using vue will inevitably use webpack, webpack 1 supports CommonJS by default, and you only need to use babel for ES2015.
    https://www.zhihu.com/question/56820346/answer/150743994

    So if you want to use this modular import syntax, the premise is that the library you reference is modular and the syntax is CommonJS.
    If you just want to import it, just add the <script> tag directly.

    reply
    0
  • Cancelreply