Javascript 应在arrow函数错误末尾返回一个值
我有这个错误,希望返回一个值在箭头函数的末尾一致返回。我不知道怎样才能防止这种情况 当屏幕大小低于1060px时,我试图停止旋转木马Javascript 应在arrow函数错误末尾返回一个值,javascript,ecmascript-6,Javascript,Ecmascript 6,我有这个错误,希望返回一个值在箭头函数的末尾一致返回。我不知道怎样才能防止这种情况 当屏幕大小低于1060px时,我试图停止旋转木马 import Swiper from 'swiper'; export default function () { let articlesGalleryCarousel; const doSomething = () => { const enableSwiper = () => {
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;
}
这是一个警告
“此规则要求将return语句设置为always或never
“指定值”
函数“breakpointChecker”在第一条IF语句中没有返回任何内容。请注意箭头函数应始终或从不返回值
有一个分支返回值(return enableSwiper();
),另一个分支不返回值(如果breakpoint.matches
为true)
那么--您希望该函数始终返回值还是从不返回值?
26:34在箭头函数一致性返回的末尾返回值时出现错误这是我得到的错误