As a VueJS student, I'm struggling to display the distances from my JSON file in a table. What is the best way to retrieve and show all the distance data for "5" and "10" by both walking and driving?
Should I use this code:
this.concurrentsRows = JSON.parse(result.data.result.iso.driving[i].poi[j].distance)
? And how should I define i and j?
Here is a snippet of my VueJS(Quasar) file:
<template>
<div>
<SimpleTableFirstCell
:loading="loading"
:columns="concurrentsColums"
:rows="concurrentsRows"
:title="Concurrents List"
/>
</div>
</template>
<script>
import { defineComponent, ref } from 'vue'
import axios from 'axios'
import SimpleTableFirstCell from 'src/components/SimpleTableFirstCell.vue'
export default defineComponent({
name: 'Concurrents',
components: {
SimpleTableFirstCell
},
data () {
return {
concurrentsColums: [
{
name: 'distance',
label: 'Distance',
field: 'distance',
},
{
name: 'latitude',
label: 'Latitude',
field: 'latitude',
},
{
name: 'longitude',
label: 'Longitude',
field: 'longitude',
}
],
loading: ref(false),
concurrentsRows: ref([]),
}
},
methods: {
concurrentsData () {
axios.get('https://url...')
.then(result => {
this.loading = true
this.concurrentsRows = JSON.parse(result.data.result)
.finally(() => {
loading.value = false
})
}
}
})
</script>
This is a sample of my JSON data:
[
{
"iso": {
"driving": {
"5": {
"poi": [
{
"distance": 1.67168887573,
"latitude": "50.415",
"longitude": "2.990",
},
{
"distance": 3.68833575679,
"latitude": "50.403",
"longitude": "3.031",
},
],
},
"10": {
"poi": [
{
"distance": 2.40512340917,
"latitude": "50.412",
"longitude": "2.977",
},
{
"distance": 2.11846991875,
"latitude": "50.417",
"longitude": "2.975",
},
],
},
},
"walking": {
"5": {
"poi": [
{
"distance": 3.68833575679,
"latitude": "50.403",
"longitude": "3.031",
}
],
},
}
}
}
]