【发布时间】:2020-04-08 07:45:21
【问题描述】:
我正在开发 Nativescript-Vue 应用程序并试图解决这个问题。
情况
我从 API 接收数据。以下是我从 api 接收到的数据结构
{
"count": 9,
"results": [
{
"id": 1,
"createdOn": "2020-04-08T12:10:46.924551+05:45",
"modifiedOn": "2020-04-08T12:10:47.236475+05:45",
"gender": "male",
"age": 32,
"status": "active",
},
{
"id": 3,
"createdOn": "2020-04-08T12:10:46.924551+05:45",
"modifiedOn": "2020-04-08T12:10:47.236475+05:45",
"gender": "male",
"age": 32,
"status": "active",
},
{
"id": 4,
"createdOn": "2020-04-08T12:10:46.924551+05:45",
"modifiedOn": "2020-04-08T12:10:47.236475+05:45",
"age": 34,
"status": "inactive",
},
{
"id": 6,
"createdOn": "2020-04-08T12:10:46.924551+05:45",
"modifiedOn": "2020-04-08T12:10:47.236475+05:45",
"age": 65,
"status": "inactive",
},
{
"id": 2,
"createdOn": "2020-04-08T12:10:46.924551+05:45",
"modifiedOn": "2020-04-08T12:10:47.236475+05:45",
"age": 19,
"status": "pending",
},
]
下面是我的vue代码。
export default {
data() {
return{
allData:[],
total:[],
active:[],
inactive:[],
pending:[]
}
},
mounted() {
axios({ method: "GET", "url": "https://api.url" }).then(
response =>
{
this.allData = response.data.results,
this.total = response.data.count
}, error => {
console.error(error);
}
)
},
computed:{
active(){
return this.allData.filter((status)=>{
return this.allData.status.match("active");
})
}
},
}
我的目标是显示应用中处于活动、非活动和待处理状态的记录数。我用这个 sn-p 来做这个活动。
<Label class="numbers" :text="active.count" width="200" height="50" />
谁能告诉我哪里失败了。
提前致谢。 Ashish A.
【问题讨论】:
-
试试
<Label class="numbers" :text="active.length" width="200" height="50" />?
标签: javascript vue.js vuejs2 nativescript nativescript-vue