From a0d1834f85b51173e02357f8a638521612fa06be Mon Sep 17 00:00:00 2001 From: wjt <1797368093@qq.com> Date: 星期三, 19 六月 2024 16:44:37 +0800 Subject: [PATCH] 添加校验 --- src/views/infomanger/banner/index.vue | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/views/infomanger/banner/index.vue b/src/views/infomanger/banner/index.vue index 65f8afc..eb09374 100644 --- a/src/views/infomanger/banner/index.vue +++ b/src/views/infomanger/banner/index.vue @@ -17,7 +17,12 @@ </div> <el-row> <el-col :span="12"> - <el-form-item :label="`璇勪环椤�${index + 1}`" style="width: 100%" :prop="item.questionName"> + <el-form-item :label="`璇勪环椤�${index + 1}`" :prop="`${index}`" style="width: 100%" :rules="[ + { + validator: validateSubField, + trigger: 'blur' + } + ]"> <el-input placeholder="璇疯緭鍏�" v-model="item.questionName" @@ -107,6 +112,8 @@ } ] }) +const instance = getCurrentInstance() + function getListEvaluate() { listEvaluate().then((val) => { form.value.questionList = val.data.questionList @@ -117,6 +124,7 @@ questionStatus: 0, questionType: 2, questionScore: 5, + questionName: '', answerList: [] }) } @@ -132,13 +140,22 @@ formRef.value.validate((valid) => { console.log(valid) if(valid) { - // saveEvaluate({questionList: form.value.questionList}).then(val => { - // ElMessage.success(item||'淇濆瓨鎴愬姛') - // }) + saveEvaluate({questionList: form.value.questionList}).then(val => { + ElMessage.success(item||'淇濆瓨鎴愬姛') + }) } }) } +function validateSubField(rule: any, value: any, callback: any) { + // console.log(rule, value) +// console.log(proxy['form']) + if(!form.value.questionList[rule.field].questionName) { + callback(new Error('璇峰叆璇勪环椤�')) + } else { + callback() + } +} function changeValue(event, index, childIndex) { // form.value.questionList[index].isScore = event.target. form.value.questionList[index].answerList.forEach((item: { isScore: number }) => { -- Gitblit v1.9.1