I want to add course.length
from the api to each item on v-select
and display the data to an activity based filter .
Items in v-select contain options all(count)
, ## filtered from online.passed
#passed(count)、
notcomplete(count)
Filter from
online.complete
vue.js template:
<template> <v-select v-model="filter" :items="items" ></v-select> <v-card v-for="online in onlineCourse" :key="online.id"> <v-card-title>{{online.title}</v-card-title> <p v-if="online.complete === 100">{{online.complete}}%</p> <p v-else-if="online.complete < 100 && online.complete > 0">{{online.complete}}%</p> <p v-else>{{online.complete}}%</p> </v-card> </template> <script> data () { return { onlineCourse: [], filter: 'All', items: [ 'All', 'passed', 'not complete', ], } } method: { async getDataOnline () { try { const request = await Axios.get('v1/courses') this.onlineCourse = request.courses } catch (error) { console.log(error.message); } } } </script>Response JSON:
"courses": [ { "id": 1, "title": "title1", "passed": false, "completed": 0 }, { "id": 2, "title": "title2", "passed": true, "completed": 100 }, { "id": 3, "title": "title3", "passed": false, "completed": 50 } ],
Some observations from the current code you posted:
online.complete === 100
but there is nocomplete
property in the online object. So correct it tocompleted
instead ofcomplete
.online.title
The closing brace is missing in the expression.Now back to the original question:
Implement counting in the
v-select
option. You have to convert the items array from anelements
array to anobjects
array.to