chain-saasui
Version:
chain-saasui
47 lines (45 loc) • 1.4 kB
JavaScript
// src/mixins/fieldMixin.js
import { isEmpty, omit } from 'chain-lodash';
export default {
computed: {
newValue: {
get() {
return !isEmpty(this.value) && this.value != null ? String(this.value) : '';
},
set(val) {
this.$emit('input', val);
},
},
textValue() {
// 默认就是 input 的文本
return this.newValue || '-';
},
attrs() {
const merged = Object.assign({}, this.defaultAttrs, this.$props, this.$attrs);
// 过滤掉一些不需要传递的属性
const exclude = ['value', 'from']; // 不需要传递给el-input的属性
return Object.keys(merged)
.filter(key => !exclude.includes(key))
.reduce((obj, key) => {
obj[key] = merged[key];
return obj;
}, {});
},
onEvents() {
return omit(this.$listeners, ['input']);
},
},
methods: {
flattenOptions(options) {
const result = [];
options.forEach(item => {
if (item.options) {
result.push(...item.options);
} else {
result.push(item);
}
});
return result;
},
},
};