es6导入:
在js文件顶端
代码语言:javascript复制import Swiper from "../../assets/javascripts/swiper.min";
import '../../assets/styles/swiper.min.css';
代码语言:javascript复制const mySwiper = new Swiper('.swiper-container', {
slidesPerView: 'auto',
centeredSlides: true,
spaceBetween: 20,
})
commonjs导入:
在js文件顶端:
代码语言:javascript复制const Swiper = require("../../assets/javascripts/swiper.min")
如果不定义Swiper名称,则会报错:
代码语言:javascript复制Uncaught ReferenceError: Swiper is not defined