I'm quite new to Vue.js and Axios. I'd like to learn it to create A REST CRUD Interface.
Starting from the HTTP GET request, the examples I've found so far all execute an HTTP GET when the page load and print the returned data. That works pretty well.
On the other hand, I need to display the data when I click a button. Here's what I have coded so far:
<script>
new Vue({
el: "#app",
data() {
return {
users: []
}
},
})
</script>
<script>
function performGetRequest1() {
axios
.get('http://localhost:8080/users')
.then(response => {
this.users = response.data,
})
.catch(function (error) {
console.log(error);
})
}
</script>
<button onclick="performGetRequest1()">Get Todos</button>
<tr v-for="user in users" :key="user.id">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.surname}}</td>
</tr>
So, I can see that when I hit the button the function correctly invokes the backend and data is returned. However, even if I set the users array to the response that is not updated in the table. I believe I should set my request to be ajax based, just my attempts so far have failed. Any help?