2019-11-02 23:09:36 +08:00
|
|
|
export default function (events = {
|
|
|
|
change: 'change',
|
|
|
|
blur: 'blur',
|
2019-11-07 21:35:26 +08:00
|
|
|
focus: 'focus'
|
2019-11-02 23:09:36 +08:00
|
|
|
}) {
|
|
|
|
return {
|
2019-12-04 17:59:38 +08:00
|
|
|
provide () {
|
|
|
|
return {
|
|
|
|
NFormItem: null
|
|
|
|
}
|
2019-11-11 12:44:36 +08:00
|
|
|
},
|
2019-11-02 23:09:36 +08:00
|
|
|
inject: {
|
|
|
|
NFormItem: {
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
Object.keys(events).forEach(event => {
|
|
|
|
const asEvent = events[event]
|
|
|
|
this.$on(event, function (value) {
|
|
|
|
if (this.NFormItem) {
|
|
|
|
this.NFormItem.$emit(asEvent, value)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2019-12-12 17:14:28 +08:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
if (this.NFormItem) {
|
|
|
|
this.NFormItem._initData()
|
|
|
|
}
|
2019-11-02 23:09:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|