export default defineComponent({
name: 'ValidateForm',
emits: ['submit-form'],
setup(props, context) {
let funcArr: ValidateFunc[] = []
let ClearInputfuncArr: ValidateFunc[] = []
const submitForm = () => {
const result = funcArr.map(func => func()).every(result => result)
console.log(result)
if (result) { ClearInputfuncArr.map(func => func()) } //此处有bug
context.emit('submit-form', result)
}
const callbackClearInput = (func: clearInputFunc) => {
funcArr.push(func)
}
const callback = (func: ValidateFunc) => {
funcArr.push(func)
}
emitter.on('formItemCreated', callback)
emitter.on('clearInput', callbackClearInput)
onUnmounted(() => {
emitter.off('formItemCreated', callback)
emitter.off('clearInput', callbackClearInput)
funcArr = []
ClearInputfuncArr = []
})
return { submitForm }
}
})
老师帮忙看看!
注明有bug处,代码逻辑当result为ture时清空input,但是为false也会清空input,一直排查不出原因