2022-10-26 11:14:13 +08:00

22 lines
621 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* getSwiperList
* @description 获取Swiper数据
* @param {Array} list 原数据
* @param {Object} options 配置
* @param {Boolean} options.circular 是否循环
* @param {Number} options.plus 左右追加个数(开启循环必填至少为2)
* @return {Array}
*/
export function getSwiperList(list, options = {
circular: true,
plus: 2
}) {
if (!options.circular) {
return list
}
const plus = options.plus || 2
const leftPlusList = [...list].reverse().slice(0, plus).reverse();
const rightPlusList = [...list].slice(0, plus);
return [].concat(leftPlusList).concat(list).concat(rightPlusList);
}