js文件中模块化导入swiper.js文件方法
es6导入:
在js文件顶端
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导入:
在js文件顶端:
const Swiper = require("../../assets/javascripts/swiper.min")
如果不定义Swiper名称,则会报错:
Uncaught ReferenceError: Swiper is not defined