最近接手了一個項目,是同事做的,我在其中新增了幾個模塊,后來同事做其他項目去了,這個項目就完全落到我身上了,當然,bug也都落到我身上了。
好了,吐槽完畢開始說正事,有個bug就是修改密碼時,二次密碼校驗失效的問題。我看代碼里確實是寫了表單校驗,就是照着element官網上那樣寫的,拿到問題就開始測試,是否執行了校驗函數,驗證確實沒有。然后百度了一些方法,有說prop和綁定的值不一樣的,但是我檢查了代碼,綁定值確實是一致的。幾經折騰發現是v-if導致的問題。
因為一個頁面里有兩個表單,所以通過v-if來控制顯隱,正是這樣,表單無法觸發校驗,改為v-show就可以了。
百度的時候看到說prop和v-modle綁定的值一定要一致,這個問題也是經常出現的,就順便記錄一下。
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"> <el-form-item label="密碼" prop="pass"> <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input> </el-form-item> <el-form-item label="確認密碼" prop="checkPass"> <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input> </el-form-item> <el-form-item label="年齡" prop="age"> <el-input v-model.number="ruleForm.age"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button> <el-button @click="resetForm('ruleForm')">重置</el-button> </el-form-item> </el-form>
總之嚴格按照例子上所寫來,就不會錯了。