vue elementui input不能輸入的問題


在 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM