vue動態設置Iview的多個Input組件自動獲取焦點


1、html,通過ref=replyBox設置焦點元素,以便后續獲取

 

// 動態設定自動獲取焦點按鈕
<p class="text-right text-blue fts14 ptb10 pointer" @click="replySet(comment,comment,1,index)" v-if="comment.replyList && comment.replyList.length > 0">我要回復</p>
// textarea輸入框
<Input class="mb10" type="textarea" v-model="replyContent" ref="replyBox" :placeholder="beReplyName ? '@ ' + beReplyName : '在這里描述你的詳細內容…'" />

 

2、js控制,必須放在this.$nextTick里面才能控制,Input如果是for循環出來的,則必須用replyBox[0]才能獲取當前的textarea

 

this.$nextTick(()=>{
    this.$refs.replyBox[0].focus()
})

 


免責聲明!

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



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