import {object, string} from 'zod'; import {useForm} from 'vee-validate'; import {toTypedSchema} from '@vee-validate/zod'; export type FormState = { name: string; password: string; company: string; }; export function useFormState() { const {handleSubmit} = useForm({ initialValues: { name: '', password: '', company: '', }, validationSchema: toTypedSchema( object({ name: string({errorMap: () => ({message: '请输入姓名'})}).min( 1, '请输入用户名', ), password: string({errorMap: () => ({message: '请输入密码'})}).min( 1, '请输入密码', ), company: string().optional(), }), ), validateOnMount: false, }); const onSubmit = handleSubmit(function(value) { console.log(value); }); return {onSubmit}; }