【发布时间】:2019-01-12 20:28:11
【问题描述】:
如何过滤列表中的重复标签,以便每个标签只列出一个?
这是我的组件代码:
<template>
<v-layout row wrap>
<ul>
<li v-for="post in sortByName(posts)" :key="post.key">
<v-chip
v-for="i in sortByName(post.tags)"
:key="i.key"
:color="`${i.color} lighten-3`"
label
small
>
<span class="pr-2">
{{ i.text }}
</span>
</v-chip>
</li>
</ul>
</v-layout>
</template>
<script>
import { mapState } from 'vuex'
const fb = require('../firebaseConfig.js')
export default {
data: () => ({
}),
computed: {
...mapState(['posts'])
},
methods: {
// function to put the tags in the right order to a -> z
sortByName (list) {
return _.orderBy(list, 'text', 'asc');
}
}
}
</script>
例如,在下面的截图中,我想过滤掉Beach,这样我在列表中只看到Beach一次:
【问题讨论】:
-
只需根据您的要求在访问原始数据的计算变量中过滤和排序列表。计算语句的返回值就是您要显示的列表。然后在模板中迭代这个计算变量。
-
好的,那看起来怎么样?
-
您的数据是什么样的?
标签: vue.js vuejs2 vuetify.js vue-filter