Currently, I am working on a Nativescript-Vue app and facing some challenges that I need help with.
The Scenario
I have data coming in from an API. Here is the structure of the data I receive:
{
"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",
},
]
This code snippet below shows the Vue component I have implemented.
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");
})
}
},
}
I aim to display the total number of records for active, inactive, and pending statuses in the app. For now, I'm focusing on the count for 'active' using this piece of code.
<Label class="numbers" :text="active.count" width="200" height="50" />
If anyone can point out where I might be making mistakes, I would greatly appreciate it.
Thank you in advance. Ashish A.