"\n\n<script lang="ts" setup>\nimport { reactive, ref } from 'vue'\nimport axios from 'axios';\nimport type { FormInstance, FormRules } from 'element-plus'\n\nconst ruleFormRef = ref()\n\nconst checkAge = (_rule: any, value: any, callback: any) => {\n if (!value) {\n return callback(new Error('Please input the age'))\n }\n setTimeout(() => {\n if (!Number.isInteger(value)) {\n callback(new Error('Please input digits'))\n } else {\n if (value < 18) {\n callback(new Error('Age must be greater than 18'))\n } else {\n callback()\n }\n }\n }, 1000)\n}\n\n\nconst ruleForm = ref({\n tid: '',\n tName: '',\n tsId: '',\n tsName: '',\n phone: '',\n age: '',\n sex: '',\n password:''\n})\naxios({\n method: 'Get',\n url: '/api/myInformationServlet',\n params: { tid: localStorage.getItem('tid') }\n}).then(function (result) {\n console.log(result);\n // 解码中文数据\n const decodedData = decodeURIComponent(result.data.data);\n // 将解码后的数据解析为 JSON 对象\n ruleForm.value = JSON.parse(decodedData);\n console.log(ruleForm.value);\n})\n\nconst rules = reactive<FormRules>({\n age: [{ validator: checkAge, trigger: 'blur' }],\n})\n\nconst submitForm = (formEl: FormInstance | undefined) => {\n if (!formEl) return\n formEl.validate((valid) => {\n if (valid) {\n axios({\n method: 'POST',\n url: '/api/myInformation',\n data: ruleForm.value\n }).then(function (result) {\n if(result.data.flag){\n alert("修改成功")\n }else{\n alert(result.data.message)\n }\n })\n } else {\n console.log('error submit!')\n return false\n }\n })\n}\n\nconst resetForm = (formEl: FormInstance | undefined) => {\n if (!formEl) return\n formEl.resetFields()\n}\n\n\n"

教师信息修改 - Element Plus 表单示例

原文地址: https://www.cveoy.top/t/topic/qxzr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录