表单
<el-form
ref="formWrap"
:model="formData"
:rules="formFules"
label-width="120px"
class="demo-ruleForm"
>
<el-form-item label="ID" prop="id">
<el-input
v-model.trim="formData.id"
placeholder="请输入ID"
clearable
/>
</el-form-item>
</el-form>
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
}
}
setup() {
const data = reactive({
// 表单参数
formData: {
id: "",
},
formWrap: null as any,
// 确定点击
confirmModal: async () => {
const formRef = unref(data.formWrap);
if (!formRef) {
return;
}
await formRef.validate((valid: boolean) => {
if (valid) {
console.log("提交拉");
}
});
},
});
const refData = toRefs(data);
return {
...refData,
};
},