You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
617 B
JavaScript
28 lines
617 B
JavaScript
10 months ago
|
import { reactive } from 'vue'
|
||
|
|
||
|
function useForm(formRef, defaultForm) {
|
||
|
const form = reactive({ ...defaultForm })
|
||
|
|
||
|
// 校验表单
|
||
|
function validateForm() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
formRef.value.validate((failList, fields) => {
|
||
|
console.log(failList, fields)
|
||
|
return (failList && failList.length) ? reject(failList) : resolve(true)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
}
|
||
|
|
||
|
// 重置表单
|
||
|
function resetForm(customForm) {
|
||
|
const rForm = customForm || defaultForm
|
||
|
form.value = { ...rForm }
|
||
|
formRef.resetFields()
|
||
|
}
|
||
|
|
||
|
return { form, validateForm, resetForm }
|
||
|
}
|
||
|
|
||
|
export default useForm
|