chem-form
Version:
使用 json 的方式便捷开发 form
41 lines (34 loc) • 1.09 kB
text/typescript
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
import { IFormItemSource } from '@/types/formItem';
import { isFunction, isArray } from '@/utils/index';
export default class extends Vue {
() value!: any;
({ type: Object }) source!: IFormItemSource;
localValue = this.value;
localSource: any[] = [];
('value', { deep: true })
listenValue(newValue) {
this.localValue = newValue;
}
('localValue', { immediate: true, deep: true })
emitUpdate(newValue: any) {
this.$emit('input', newValue);
this.$emit('update:value', newValue);
}
async created() {
const { labelKey, valueKey, data } = this.source;
let _localSource: any[] = [];
if (isArray(data)) {
_localSource = data as [];
} else if (isFunction(data)) {
_localSource = (await (data as Function)()) || [];
}
this.localSource = _localSource.map(item => ({
label: item[labelKey],
value: item[valueKey],
// NODE: 用于控制每个选项的禁用
disable: item.disable || false
}));
}
}