javascript - 专注于 v-for 问题中的 textarea
问题描述
我有意见和回复。
当我单击评论上的回复按钮时,我希望它专注于折叠的文本区域。
自从它是评论部分以来,有很多文本区域..
<div class="bg-white border shadow-soft p-4 mb-4" v-for="comment in comments" :key="comment.id"
回复按钮:
<b-button class="text-action font-weight-light font-small" v-b-toggle="'collapse-'+comment.id" @click="focusTextArea('replay'+comment.id)">
<i class="fas fa-reply mr-2"></i> رد</b-button>
文本区域:
<b-collapse :id="'collapse-'+comment.id">
<textarea class="form-control " v-model="reply" placeholder="Reply to John Doe" rows="6" :ref="'replay'+comment.id"></textarea>
<div class="d-flex justify-content-between mt-3"><small class="font-weight-light"><span >1000</span> characters remaining</small>
<button class="btn btn-primary btn-sm animate-up-2" type="button" @click="replyTo(comment)">send</button>
</div>
</b-collapse>
我试过这个:
focusTextArea(textarea) {
this.$nextTick(() => {
this.$refs[textarea][0].focus();
});
},
然后点击上面的按钮^。
当我单击按钮时没有任何反应,但是当我单击按钮返回时,textarea 被折叠,并且焦点在其折叠时出现:\
知道这里有什么问题吗?
解决方案
我为此创建了一个codepen。
到目前为止,您的方法是正确的,但请记住,折叠元素有一个动画,您应该在触发focus()
.
https://codepen.io/elsib/pen/GROEVRe
推荐阅读
- deep-learning - 如何从 vgg19 中移除自适应平均池层?
- android - 带有 Recyclerview 的 MotionLayout 中的 SwipeRefreshLayout 忽略点击事件
- git - 无法使用“git rm -r -f {folder_name}”删除所有文件(Windows 10)
- thrift - 如何在 Apache Thrift 中表示一种类型的值?
- java - 如何在 SQLite 中使用 android 中的多个数据库助手类进行内部连接
- python-3.x - 从 Fuzzywuzzy 获取匹配的令牌列表
- r - 如何使用 case_when 和 mutate_all 插入变量值
- javascript - 如何使用数组或对象中的值在 Google 表格中动态创建下拉列表?
- javascript - 为什么 Javascript DOM 有这种奇怪的行为?
- java - 如何解决 SAXParseException: cvc-elt.1 -> 'bpm-platform'?