【发布时间】:2018-07-04 18:10:40
【问题描述】:
我已经在 Vue 中准备了带有标签分组的标签输入控件。模板包括:
<script type="text/x-template" id="tem_vtags">
<div class="v-tags">
<ul>
<li v-for="(item, index) in model.items" :key="index" :data-group="getGroupName(item)"><div :data-value="item"><span v-if="typeof model.tagRenderer != 'function'">{{ item }}</span><span v-if="typeof model.tagRenderer == 'function'" v-html="tagRender(item)"></span></div><div data-remove="" @click="remove(index)">x</div></li>
</ul>
<textarea v-model="input" placeholder="type value and hit enter" @keydown="inputKeydown($event,input)"></textarea>
<button v-on:click="add(input)">Apply</button>
</div>
</script>
我已经定义了名为 .getGroupName() 的组件方法,它依赖于可以在 props 上设置的名为 .qualifier() 的其他函数。
我的问题:一旦我将任何标签添加到集合 (.items) 中,当我在 textarea 中为每个 keydown 输入任何内容时,.getGroupName() 似乎被调用了。看起来像在 textarea 中输入任何内容会导致所有组件重新渲染?
你知道如何避免这种行为吗?我希望 .getGroupName 只有在添加新标签时才会被调用。
完整代码如下:
https://codepen.io/anon/pen/bKOJjo?editors=1011(我已放置 debugger; 以在运行时进入 .qualifier() 时捕获。
任何帮助appriciated。
男人
【问题讨论】:
标签: vuejs2