chore(Collapse): improve warning (#8119)

This commit is contained in:
neverland 2021-02-10 10:44:46 +08:00 committed by GitHub
parent 708d57ea77
commit faab7c03f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,15 +41,19 @@ export default createComponent({
const isExpanded = (name) => {
const { accordion, modelValue } = props;
if (
!accordion &&
!Array.isArray(modelValue) &&
process.env.NODE_ENV !== 'production'
) {
console.error(
'[Vant] Collapse: type of prop "modelValue" should be Array'
);
return;
if (process.env.NODE_ENV !== 'production') {
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 accordion ? modelValue === name : modelValue.indexOf(name) !== -1;