mirror of
https://github.com/youzan/vant.git
synced 2025-10-16 08:00:34 +00:00
refactor: replace find method for improved readability (#13395)
This commit is contained in:
@@ -49,7 +49,7 @@ export const isOptionExist = (
|
|||||||
fields: Required<PickerFieldNames>,
|
fields: Required<PickerFieldNames>,
|
||||||
) =>
|
) =>
|
||||||
value !== undefined &&
|
value !== undefined &&
|
||||||
!!options.find((option) => option[fields.value] === value);
|
options.some((option) => option[fields.value] === value);
|
||||||
|
|
||||||
export function findOptionByValue(
|
export function findOptionByValue(
|
||||||
options: PickerOption[],
|
options: PickerOption[],
|
||||||
|
@@ -59,7 +59,7 @@ export default defineComponent({
|
|||||||
const { $route } = vm;
|
const { $route } = vm;
|
||||||
const { to } = props;
|
const { to } = props;
|
||||||
const config = isObject(to) ? to : { path: to };
|
const config = isObject(to) ? to : { path: to };
|
||||||
return !!$route.matched.find((val) => {
|
return $route.matched.some((val) => {
|
||||||
const pathMatched = 'path' in config && config.path === val.path;
|
const pathMatched = 'path' in config && config.path === val.path;
|
||||||
const nameMatched = 'name' in config && config.name === val.name;
|
const nameMatched = 'name' in config && config.name === val.name;
|
||||||
return pathMatched || nameMatched;
|
return pathMatched || nameMatched;
|
||||||
|
@@ -267,12 +267,11 @@ export default defineComponent({
|
|||||||
name: Numeric,
|
name: Numeric,
|
||||||
skipScrollIntoView?: boolean,
|
skipScrollIntoView?: boolean,
|
||||||
) => {
|
) => {
|
||||||
const matched = children.find(
|
const index = children.findIndex(
|
||||||
(tab, index) => getTabName(tab, index) === name,
|
(tab, index) => getTabName(tab, index) === name,
|
||||||
);
|
);
|
||||||
|
|
||||||
const index = matched ? children.indexOf(matched) : 0;
|
setCurrentIndex(index === -1 ? 0 : index, skipScrollIntoView);
|
||||||
setCurrentIndex(index, skipScrollIntoView);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollToCurrentContent = (immediate = false) => {
|
const scrollToCurrentContent = (immediate = false) => {
|
||||||
|
Reference in New Issue
Block a user