Having trouble importing JSON results into a Vue component?
The results are as follows:
[{"id":"d023c5e3-ca3c-4d97-933a-1112a8516eee",
"score":9001,
"updated":"2018-12-07T13:48:33.6366278",
"player":Johanna,
"category":Funny},
{"id":"398b65fb-e741-4801-be49-926b111ec871",
"score":99,
"updated":"2018-12-11T11:13:42.8312936",
"player":Johanna,
"category":Music}]
Code in GetResult.js:
import axios from 'axios'
const url = 'http://localhost:5000/api/Results';
export default {
data () {
return {
results: {}
}
},
created () {
axios.get(url)
.then(response => {
console.log(response.data)
this.$data.results = response.data
})
.catch(err => {
console.log(err)
})
}
}
Code in Toplist.vue:
<template>
<div class="TopList">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Score</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr v-for="result in resultList" :key="result.id">
<td>{{ result.player }}</td>
<td>{{ result.score }}</td>
<td>{{ result.category }}</td>
</tr>
</tbody>
</table>
</div>
<script>
import results from './ResultApi/GetResult.js'
export default {
name: 'TopList',
data() {
return {
resultList: results
}
}
}
</script>