在 vue 2.6.10 版本遇到了 首次進行編輯input 可以正常輸入 但是再次進入不能正常輸入,是因為我對input綁定的是對象內的變量,首次進入關閉之后我進行了對象的重置直接置為空對象,這樣會導致這種錯誤的發生;
//template <el-input v-model="myObj.input1"/> <el-input v-model="myObj.input2"/> //data里的數據 myObj:{ input1:"", input2: "", } //methods中在關閉時進行重置 reset 這種重置方式 導致上面的問題 reset(){ myObj:{} }
解決方法:
方案1:重置時 精確到對應的變量
reset(){ myObj:{ input1:"", input2: "", } }
方案2:給input綁定@input事件 有內容輸入就實時更新視圖
<el-input v-model="myObj.input1" @input="updateView($event)" /> <el-input v-model="myObj.input2" @input="updateView($event)" /> //methods updateView(e) { this.$forceUpdate() }
方案3:綁定到input中的雙向數據變量 不是對象內部的值就不會遇到這個問題
<el-input v-model="input1" @input="updateView($event)" /> <el-input v-model="input2" @input="updateView($event)" /> //data input1: "", input2: ""
參考:https://www.cnblogs.com/xhliang/p/11940418.html