如何将 Swiper.js 转换为 ES5
我使用 babel 来转换它,但刷卡器无法工作,并且在控制台中显示此错误。
我转到发生此错误的行并添加 console.log()
。
if (params.el && $(params.el).length > 1) {
var swipers = [];
console.log($(params.el))
$(params.el).each(function (containerEl) {
var newParams = extend({}, params, {
el: containerEl
});
swipers.push(new Swiper(newParams));
});
return swipers;
} // Swiper Instance
获取这些元素没有问题,但不知怎的 $(...).each
就是不起作用。
我该怎么做才能解决这个问题?
或者转换的时候出了什么问题?
我的 .babel 很简单,如下
{
"presets": ["es2015"]
}
我使用 gulp-babel 来转换它。 在package.json
中:
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"gulp": "^4.0.2",
"gulp-babel": "^7.0.1",
"url-search-params-polyfill": "^8.1.1"
},
"devDependencies": {
"babel-preset-es2015": "^6.24.1"
},
在gulpfile.js
中:
function to_es5() {
gulp
.src("./src/js/*.js")
.pipe(
babel({
presets: ["es2015"], })
)
.pipe(gulp.dest("./src/js-es5/"))
}
I use babel to convert it but the swiper is not working and it shows this error in console.
I go to the line where this error happen and add console.log()
.
if (params.el && $(params.el).length > 1) {
var swipers = [];
console.log($(params.el))
$(params.el).each(function (containerEl) {
var newParams = extend({}, params, {
el: containerEl
});
swipers.push(new Swiper(newParams));
});
return swipers;
} // Swiper Instance
There's no problem getting these elements but somehow $(...).each
just doesn't work.
What can i do to fix this?
Or is there something wrong when converting?
My .babel
is simple, as below
{
"presets": ["es2015"]
}
I use gulp-babel
to convert it.
In package.json
:
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"gulp": "^4.0.2",
"gulp-babel": "^7.0.1",
"url-search-params-polyfill": "^8.1.1"
},
"devDependencies": {
"babel-preset-es2015": "^6.24.1"
},
And in gulpfile.js
:
function to_es5() {
gulp
.src("./src/js/*.js")
.pipe(
babel({
presets: ["es2015"], })
)
.pipe(gulp.dest("./src/js-es5/"))
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论