naive-ui/packages/mixins/asformitem.js
2019-11-11 12:44:36 +08:00

27 lines
487 B
JavaScript

export default function (events = {
change: 'change',
blur: 'blur',
focus: 'focus'
}) {
return {
provide: {
NFormItem: null
},
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)
}
})
})
}
}
}