【发布时间】:2019-07-16 17:50:35
【问题描述】:
是否可以从 API 和 Vue 中的数据创建 A-Z 字母列表 (like this),以便能够确定数据中的属性是否包含以哪个字母开头的名称。如果数据不包含特定的字母名称,则从字母锚标记中删除/禁用 href 属性。
在链接的示例中,缺少字母 K、X 和 Z,因为它们没有数据
JSON
[
{
"id": 77,
"link": "http://my-site/cosmoquotes/authors/anonymous/",
"name": "Anonymous",
"slug": "anonymous"
},
{
"id": 72,
"link": "http://my-site/authors/ferdinand-marcos/",
"name": "Ferdinand Marcos",
"slug": "ferdinand-marcos"
},
{
"id": 75,
"link": "http://my-site/authors/john-f-kennedy/",
"name": "John F. Kennedy",
"slug": "john-f-kennedy"
},
{
"id": 67,
"link": "http://my-site/authors/john-maxwell/",
"name": "John Maxwell",
"slug": "john-maxwell"
}
]
组件
export default {
data() {
return {
authorsRequest: {
type: 'authors',
params: {
per_page: 100
}
},
}
},
computed: {
authors () {
return this.$store.getters.requestedItems(this.authorsRequest)
},
},
methods: {
getAuthors() {
return this.$store.dispatch('getItems', this.authorsRequest)
},
},
created() {
this.getAuthors()
}
}
因此,根据返回的数据,只有字母“A”、“F”和“J”应该是可点击/显示的。
【问题讨论】:
标签: vue.js