【发布时间】:2017-06-03 18:05:27
【问题描述】:
我正在使用以下代码来显示数组中的类别。该数组可能包含重复的类别。有什么办法我只能在 VueJS 中选择独特的元素?
<li v-for="product in products">
{{product.category}}
</li>
数组:
products: [
{ id: '1', title: 'Test 1', category: 'Test 3' },
{ id: '2', title: 'Test 2', category: 'Test 1' },
{ id: '3', title: 'Test 3', category: 'Test 2' },
{ id: '3', title: 'Test 4', category: 'Test 1' },
{ id: '5', title: 'Test 5', category: 'Test 3' }
]
【问题讨论】:
-
这是一个数组,所以过滤它的重复值。也许使用
_.uniqBy -
对不起,我是 VueJS 的新手。听说vuejs2没有过滤选项
标签: vue-component vuejs2 vue.js