Browse Source

guipRadio 组件优化

pull/83/head
zq 2 days ago
parent
commit
2d5a0f9eda
  1. 34
      src/components/GuipRadio.vue

34
src/components/GuipRadio.vue

@ -26,8 +26,18 @@ export default {
// :
// 1. : [{ label: '', value: '', disabled: false }]
// 2. : { key1: 'value1', key2: 'value2' }
// 3.null
// 4.
options: {
type: [Array, Object],
// type: [Array, Object],
default: () => null,
validator: (value) => {
// null
return value == null ||
value === '' ||
Array.isArray(value) ||
(typeof value === 'object' && value !== null)
},
required: true,
},
// 使 v-model
@ -73,16 +83,26 @@ export default {
computed: {
//
normalizedOptions() {
//
// nullundefined
if (this.options == null || !this.options) {
return [];
}
//
if (Array.isArray(this.options)) {
return this.options;
} else if (typeof this.options === 'object' && this.options !== null) {
//
return Object.keys(this.options).map(key => ({
return this.options.length ? this.options : [];
}
//
if (typeof this.options === 'object') {
const keys = Object.keys(this.options);
return keys.length ? keys.map(key => ({
key,
value: this.options[key]
}));
})) : [];
}
//
return [];
}
},

Loading…
Cancel
Save