【发布时间】:2019-09-09 23:17:29
【问题描述】:
我正在尝试添加在单击某些内容时从数组中删除项目的功能。我目前有:
<span @click="deleteItem(index)" v-for="(item, index) in customTaxonomies.featured" v-html="item"></span>
然后在我的方法中我有:
deleteItem: function(index) {
this.customTaxonomies.featured.splice(index, 1);
}
所以这行得通,但我想要影响的数组需要在我的方法中知道才能做到这一点(customTaxonomies.featured)。有没有办法通过 v-for 循环传递我想要定位的数组的名称,就像我对 index 所做的那样?
所以可能是这样的:
<span @click="deleteItem(index, arrayName)" v-for="(item, index, arrayName) in customTaxonomies.featured" v-html="item"></span>
deleteItem: function(index, arrayName) {
this.arrayName.splice(index, 1);
}
或者通过前端的道具或其他东西传递数组的名称?我的主要目标是使用我的应用程序的前端传递我要从中删除项目的数组的名称。
【问题讨论】:
-
你传递的是
array本身而不是数组名,虽然这不是一个好主意
标签: javascript arrays loops vue.js