要實現這個功能其實並不難,element組件直接用就能夠,ios
可是我在使用過程當中碰到了幾個坑,就記錄下來,分享給你們,避免落坑,話很少說,直接上過程......axios
表單校驗功能:app
實現這個功能,總共分爲如下4布:async
template代碼:post
1 <el-form 2 :model="Opinion" 3 ref="MyOpinion" 4 :rules="rules" 5 size="small" 6 class="lj-form lj-form-s1" 7 > 8 <el-form-item label="審覈意見: " prop="txt" style="margin-bottom:25px;"> 9 <el-input type="textarea" :rows="5" v-model="Opinion.txt"></el-input> 10 </el-form-item> 11 </el-form>
data定義數據代碼:ui
1 data() { 2 return { 3 Opinion: { 4 radio: "1", 5 txt: "", 6 value: "" 7 }, 8 rules: { 9 txt: [{ required: true, message: "請輸入審覈意見", trigger: "blur" }] 10 } 11 }; 12 },
methods方法代碼:this
1 async approval() { 2 let _this = this; 3 this.$refs.MyOpinion.validate(async valid => { 4 if (valid) { 5 const res2 = await _this.$axios.post(`/approve/approve_refuse`, { 6 ...obj 7 }); 8 if (res2.data.error == 0) { 9 _this.$message.success(res2.data.message); 10 } 11 _this.innerVisible = false; 12 _this.visibleApply = false; 13 } 14 }); 15 }