vue项目引用Swiper.js在低版本浏览器出现错误

如果项目有轮播翻页等效果,可以通过swiper实现

npm i swiper -S

在低版本浏览器下使用,会出现es6语法的无法解析。需要将es6转为es5,一般情况下只需要在transpileDependencies中增加依赖包名的配置即可。Swiper.js 这个 npm 包里面还使用了 dom7 和 ssr-window,所以需要对这两个插件进行 Babel 转 ES5。

解决方案如下

module.exports = {
  transpileDependencies: [
    "swiper",
    "dom7",
    "ssr-window",
  ], // 默认babel-loader忽略mode_modules,这里可增加例外的依赖包名
}

  

原文地址:https://www.cnblogs.com/gao-xiaomeng/p/14420170.html