使用vue js或jquery替换元素中的对象
我有一个组件,在其中我使用v-for循环通过对象数组使用vue js或jquery替换元素中的对象,jquery,vuejs2,Jquery,Vuejs2,我有一个组件,在其中我使用v-for循环通过对象数组 <div v-for="item in goods" class="ui fluid card" :key="item.id" :id="item.id"> <div v-for="badge in item.badges" :key="badge.id" class="ui labels"> <a class="ui label" :style
<div v-for="item in goods" class="ui fluid card" :key="item.id" :id="item.id">
<div v-for="badge in item.badges" :key="badge.id" class="ui labels">
<a
class="ui label"
:style="{ backgroundColor: '#'+ badge.color, color: '#fff'}"
>{{badge.label}}</a>
</div>
<button @click="replacement(item) "class="circular ui icon yellow button replacement">
<div>
<span style="font-size:25px">
<strong v-if="item.related_goods!=null">{{item.related_goods.length}}</strong>
<strong v-else>0</strong>
</span>
<span style="padding:1px">
<small style="font-size:12px;">Replacement</small>
</span>
</div>
</button>
<button @click="complement(item) class="circular ui icon red button complementary">
<div>
<span style="font-size:25px">
<strong v-if="item.alternative_goods!=null">{{item.alternative_goods.length}}</strong>
<strong v-else>0</strong>
</span>
<span>
<small style="font-size:12px">Complement</small>
</span>
</div>
</button>
{{badge.label}
{{{item.related_-goods.length}
0
替换
在vue中直接数组分配
e、 g.a[i]=vue未检测到该值
Vue提供了数组变异方法来改变数组中的值,这将促进dom的刷新
在您的示例中,使用slice方法
vm.item.splice(indexOfItem, 1, newValue)
请参见使用拼接方法
vm.item.splice(indexOfItem, 1, newValue)
项是数组
indexOfItem是起始索引。
1是要删除的金额。
newValue是要插入的值
使用变异方法vue可以检测数组中的更改,并相应地更新dom。如果我理解正确,您可以简单地更新货物
数组,更改应立即反映在视图中。否则,“替换项目”是什么意思?