[英]Return array with filter object at specific index in vue
I want to remove an object at index 2 and return array in computed.我想删除索引 2 处的 object 并在计算中返回数组。
I can do it in div with v-for & v-if but it some warning.我可以用 v-for & v-if 在 div 中做到这一点,但它有一些警告。
<div
v-for="(index, i) in sameImage"
v-if="i !== 2"
>
</div
How to it in computed with filter.如何使用过滤器计算它。
sameImage:function () {
const ar = this.MainImg;
return ar.filter();
}
You could add the index as the second parameter of the filter callback:您可以将索引添加为过滤器回调的第二个参数:
return ar.filter((_,i)=>i!==2);
or separate the v-if
and v-for
in different elements like:或将
v-if
和v-for
分隔在不同的元素中,例如:
<template v-for="(index, i) in sameImage">
<div v-if="i !== 2">
{{index}}
</div>
</template>
template
is not the root one, it's a virtual element that will not be rendered in the DOM template
不是根,它是一个虚拟元素,不会在 DOM 中呈现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.