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() })