最近在写移动端swiper 时候遇到ESLint:Do not use 'new' for side effects.(no-new))错误导致编译一直不通过,原代码如下:使用了new关键字
new Swiper('.swiper-container', {
autoplay: {
delay: 3000,
disableOnInteraction: false
},
centeredSlides: true,
spaceBetween: 30,
pagination: {
el: '.swiper-pagination',
clickable: true
},
loop: true
})
该错误可通过添加eslint-disable-line注释可以绕过规则检测,修改后的代码如下:
new Swiper('.swiper-container', { // eslint-disable-line
autoplay: {
delay: 3000,
disableOnInteraction: false
},
centeredSlides: true,
spaceBetween: 30,
pagination: {
el: '.swiper-pagination',
clickable: true
},
loop: true
})
之后编译,完美的运行。