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

 

posted @ 2019-07-03 15:14  蓓蕾心晴  阅读(2120)  评论(0编辑  收藏  举报