首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何跟踪VueJS数组中的哪些项已被用户更改?

如何跟踪VueJS数组中的哪些项已被用户更改?
EN

Stack Overflow用户
提问于 2018-10-12 15:55:04
回答 1查看 29关注 0票数 1

我有一个或多个对象,每个对象都有一些属性。我使用一个v-for来使用v-model创建一个具有文本输入的表,这样用户就可以对他们想要的任何项的属性进行更改。

我想要做的,是跟踪哪些项目已被用户变异。理想情况下,我会将该项的"mutated"属性更改为true。这将使我能够轻松地进行可视更改,从而提醒用户保存对该元素的更改。

现在,我正在使用@keydown,但是可能有人会用鼠标粘贴/剪切。

下面是我现在的代码:

代码语言:javascript
复制
<tr v-for="(item, index) in Items" v-if="item.Active == 1" v-bind:class="{ 'mutated': item.mutated }">
<td>{{item.Keyword}}</td>
<td><input type="text" class="form-control" v-model="item.ID" @keydown="mutated(index)"></td>
<td><input type="text" class="form-control" v-model="item.Title" @keydown="mutated(index)"></td>
<td class="text-center pt-2">{{item.Inquiries}}</td>
<td>
    <button class="btn btn-sm btn-outline-danger" v-on:click="deactivate_pairing(index, item.ID)"><i class="material-icons">cancel</i></button>
    <button class="btn btn-sm"  v-bind:class="{ 'btn-success': item.mutated, 'btn-outline-success': !item.mutated }" v-on:click="update_pairing(index, item.ID)"><i class="material-icons">save</i></button>
</td>

您能提供的任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-12 16:02:35

也许我误解了你的问题,但你就不能直接使用@change吗?

代码语言:javascript
复制
<td><input type="text" class="form-control" v-model="item.ID" @change="mutated(index)"></td>

您也可以使用@input

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52783086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档