Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@redamoon
Created July 28, 2021 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redamoon/21779331079550d55f526847e3cd0233 to your computer and use it in GitHub Desktop.
Save redamoon/21779331079550d55f526847e3cd0233 to your computer and use it in GitHub Desktop.
poPLzzd
<div id="app">
<div v-for="(v, i) in fliterTagList">
<div>{{ v.label }}</div>
</div>
</div>
const endpoint = {
"contents": [
{
"tag": [
{
"id": "4-p2z49d-2na",
"createdAt": "2021-07-26T13:49:21.242Z",
"updatedAt": "2021-07-26T13:49:21.242Z",
"publishedAt": "2021-07-26T13:49:21.242Z",
"revisedAt": "2021-07-26T13:49:21.242Z",
"label": "Next.js",
"slug": "Nextjs"
},
{
"id": "4-p2z49d-2na",
"createdAt": "2021-07-26T13:49:21.242Z",
"updatedAt": "2021-07-26T13:49:21.242Z",
"publishedAt": "2021-07-26T13:49:21.242Z",
"revisedAt": "2021-07-26T13:49:21.242Z",
"label": "Movable Type",
"slug": "Movabletype"
}
]
},
{
"tag": [
{
"id": "4-p2z49d-2na",
"createdAt": "2021-07-26T13:49:21.242Z",
"updatedAt": "2021-07-26T13:49:21.242Z",
"publishedAt": "2021-07-26T13:49:21.242Z",
"revisedAt": "2021-07-26T13:49:21.242Z",
"label": "Next.js",
"slug": "Nextjs"
}
]
}
],
"totalCount": 2,
"offset": 0,
"limit": 10
}
const vm = new Vue({
el: '#app',
data() {
return {
data: endpoint
}
},
computed: {
fliterTagList() {
const getTagList = this.data.contents.map((v, i) => v.tag).flat(1)
return [...new Map(getTagList.map(v => [v.label, v])).values()]
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment