gpt4 book ai didi

javascript - 期望在箭头函数错误的末尾返回一个值

转载 作者:行者123 更新时间:2023-12-02 03:23:59 27 4
gpt4 key购买 nike

我有这个错误 Expected to return a value at the end of arrow function consistent-return。我不确定如何防止这种情况。

我试图在屏幕尺寸低于 1060 像素时停止 Swiper 轮播

    import Swiper from 'swiper';

export default function () {
let articlesGalleryCarousel;

const doSomething = () => {
const enableSwiper = () => {
articlesGalleryCarousel = new Swiper('.js-swiper-container', {
loop: true,
slidesPerView: 'auto',
centeredSlides: true,
a11y: true,
keyboardControl: true,
grabCursor: true,
pagination: '.swiper-pagination',
paginationClickable: true,
navigation: {
nextEl: '.carousel-button--prev',
prevEl: '.carousel-button--next',
},
});
};

const breakpoint = window.matchMedia('(max-width:1060px)');

const breakpointChecker = () => {
if (breakpoint.matches === true) {
if (articlesGalleryCarousel !== undefined) articlesGalleryCarousel.destroy(true, true);
} else if (breakpoint.matches === false) {
return enableSwiper();
}
};

breakpoint.addListener(breakpointChecker);

breakpointChecker();
};
return doSomething;
}

最佳答案

这是一个 ESLint consistent-return警告。

"This rule requires return statements to either always or never specify values"

在第一个 IF 语句的情况下,您的函数“breakpointChecker”没有返回任何内容。

关于javascript - 期望在箭头函数错误的末尾返回一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53960764/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com