vue-ele-form-yd
Version:
基于 element-ui 的数据驱动表单组件
40 lines (37 loc) • 1.08 kB
JavaScript
import dayjs from 'dayjs'
export default {
data () {
return {
type: 'Array'
}
},
methods: {
handleChange (value) {
let newVal = value
if (newVal && Array.isArray(value) && !(this.attrs.valueFormat || this.attrs['value-format'])) {
newVal = newVal.map(date => {
return dayjs(date).unix()
})
}
this.$emit('input', newVal)
},
// 获取值: 数字(秒 -> 毫秒) / 字符串
getValue (value) {
if (Array.isArray(value) && !(this.attrs.valueFormat || this.attrs['value-format'])) {
value = value.map(date => {
return typeof date === 'number' ? date * 1000 : date
})
}
return value
},
// 自定义值, dataModel=>newValue
customInit (value) {
if (Array.isArray(value) && this.attrs && !(this.attrs.displayFormat || this.attrs['display-format'])) {
value = value.map(date => {
return typeof date === 'number' ? date * 1000 : date
})
}
return value
}
}
}