【发布时间】:2020-11-19 12:21:47
【问题描述】:
我有 Vue 应用程序,我想在评论表单中添加受 Facebook 启发的按钮。我有一个可以工作的普通 JS 原型。当我尝试将其合并到 Vue 应用程序中时,我遇到了页面上多次出现该组件的问题,因为它大量使用了元素 ID。我可以声明动态 id,但这种方法效果不佳,因为 <style> 是静态的。后来我找到了refs,并受到这篇精彩文章的启发:https://www.telerik.com/blogs/how-to-target-the-dom-in-vue。长话短说:我的回调永远不会被调用。
源代码:
<b-form-textarea
class="textarea" ref="textareaRef"
rows="1" max-rows="8"
@oninput.native = "adjustIconsInTextarea"
:placeholder="$t('comment.write-comment-placeholder')"
v-model="text"
>
<div class="icons" ref="iconsRef">
<b-button :id="`emoji_list_${commentId}`" class="mt-2" variant="outline" size="sm">
😀
</b-button>
</div>
methods: {
adjustIconsInTextarea() {
const textComment = this.$refs.textareaRef;
console.log(textComment.value.length);
const icons = this.$refs.iconsRef;
if (textComment.value.length > 140) {
textComment.style.padding = '13px 50px 34px 32px';
icons.style.top = '-36px';
icons.style.right = '72px';
} else {
textComment.style.padding = '10px 174px 5px 28px';
icons.style.top = '-45px';
icons.style.right = '68px';
}
},
Bootstrap-vue b-form-textarea 的 events。哪里出错了?
【问题讨论】:
-
你应该使用
@input= "adjustIconsInTextarea" -
就是这样,谢谢。
标签: javascript vue.js vuejs2 vue-component bootstrap-vue