前言
swiper这是一个很强大的轮播展示工具,但往往也会有一些未知BUG,尤其是在手机端,由于性能局限,会导致效果和PC测试的时候有完全不一样的效果
在H5项目中,需要用到翻页效果,通过 Swiper 来实现,安装 Swiper
npm i swiper -S
但是实际使用中,发现低版本 iOS < 11 会出现下面这个错误:
SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.
原因
Swiper.js 这个 npm 包里面还使用了 dom7 和 ssr-window,所以需要对这两个插件进行 Babel 转 ES5
解决方案
Vue CLI 2.x 下,在 build/webpack. .config.js 文件中修改
// ...
modules: {
rules: [
// ...
{
test: /\.js$/,
loader: 'babel-loader',
include: [
resolve('src'),
resolve('test'),
resolve('node_modules/swiper/dist/js/'),
resolve('node_modules/webpack-dev-server/client'),
// 新增
resolve('node_modules/swiper'),
resolve('node_modules/dom7'),
resolve('node_modules/ssr-window')
]
},
// ...
]
}
// ...
Vue CLI 3.x 下
在 vue.config.js 中增加 transpileDependencies 配置
module.exports = {
transpileDependencies: [
"swiper",
"dom7",
"ssr-window"
]
}
参考:http://idangero.us/swiper/get-started/
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
上一篇 :
云栖科技评论88期:量子计算的AB面
-
中小型企业运维之路
2026-05-18栏目: 教程
-
云原生生态周报 Vol. 19 | Helm 推荐用户转向 V3
2026-05-18栏目: 教程
-
使用自定义指标进行Pod弹性伸缩
2026-05-18栏目: 教程
-
3个点说清楚分库分表扩容问题
2026-05-18栏目: 教程
-
RocketMQ 多副本前置篇:初探raft协议
2026-05-18栏目: 教程
