mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: extract validateModelValue (#8807)
This commit is contained in:
parent
0c71982db9
commit
6128434e22
@ -12,6 +12,25 @@ export type CollapseProvide = {
|
|||||||
isExpanded: (name: number | string) => boolean;
|
isExpanded: (name: number | string) => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function validateModelValue(
|
||||||
|
modelValue: string | number | Array<string | number>,
|
||||||
|
accordion: boolean
|
||||||
|
) {
|
||||||
|
if (accordion && Array.isArray(modelValue)) {
|
||||||
|
console.error(
|
||||||
|
'[Vant] Collapse: "v-model" should not be Array in accordion mode'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!accordion && !Array.isArray(modelValue)) {
|
||||||
|
console.error(
|
||||||
|
'[Vant] Collapse: "v-model" should be Array in non-accordion mode'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name,
|
name,
|
||||||
|
|
||||||
@ -55,19 +74,11 @@ export default defineComponent({
|
|||||||
const isExpanded = (name: number | string) => {
|
const isExpanded = (name: number | string) => {
|
||||||
const { accordion, modelValue } = props;
|
const { accordion, modelValue } = props;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (
|
||||||
if (accordion && Array.isArray(modelValue)) {
|
process.env.NODE_ENV !== 'production' &&
|
||||||
console.error(
|
!validateModelValue(modelValue, accordion)
|
||||||
'[Vant] Collapse: "v-model" should not be Array in accordion mode'
|
) {
|
||||||
);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!accordion && !Array.isArray(modelValue)) {
|
|
||||||
console.error(
|
|
||||||
'[Vant] Collapse: "v-model" should be Array in non-accordion mode'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return accordion
|
return accordion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user