I am eager to use VueJS to process data from my JSON source
Here is an example of the data structure:
JSON obtained via API
[
{
"id": 4,
"votes": 0
},
{
"id": 3,
"votes": 1
},
]
In order to fetch and display this data, I have implemented the following VueJS script:
app.js
const vm = new Vue({
el: '#app',
data: {
results: []
},
mounted() {
axios.get("http://example.com/votes.json")
.then(response => {this.results = response.data})
},
});
My next task is to create a Vue variable that will show the total number of votes in my index.html file.
index.html
<div v-for="result in results">
<p>Votes {{ result.votes }}.</p>
<p>Id : {{ result.id }}</p>
</div>
<div>
<p>Total Votes: {{ resultsVotes }}</p>
</div>