es6導入:javascript
在js文件頂端css
import Swiper from "../../assets/javascripts/swiper.min";
import '../../assets/styles/swiper.min.css';
const mySwiper = new Swiper('.swiper-container', { slidesPerView: 'auto', centeredSlides: true, spaceBetween: 20, })
commonjs導入:java
在js文件頂端:es6
const Swiper = require("../../assets/javascripts/swiper.min")
若是不定義Swiper名稱,則會報錯:ide
Uncaught ReferenceError: Swiper is not defined