element ui中input在輸入一個字符或者刪除一個字符就會失去光標,需要重新聚焦的才能繼續操作的原因


今天在修改前段頁面,添加字段展示的時候出現了一個問題,之前從來沒有遇到過,就是el-input輸入框輸入一個字符之后就失去了光標聚焦,要想重新輸入之后,就必須要重新點擊光標聚焦才行;

排查之后才發現是綁定的key的原因;我的el-input是循環生產的,需要綁定一個key值,key值我用了一個userId,乍一看沒什么問題,問題就在我后續的操作上,我在v-model的時候,也用了一個userId,

這樣就造成了,當我修改userId的時候,就會造成key值修改,然后對應的DOM也會重新渲染,所以就會造成上述問題;

<el-input  v-for="params of managerUserList" 
       :key="params.userId"  //key值也用了userId
       v-model="params.userId">
    <template slot="prepend">{{params.name}}    </template>
 </el-input>        

修改后的代碼為:

<el-input  v-for="params of addManagerForm.managerUserList" 
                  :key="params.loginName" 
                  v-model="params.userId">
                  <template slot="prepend">{{params.name}}</template>
              </el-input>

key值是唯一標識元素的標志


免責聲明!

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



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