You mean the students array is never populated or the {{ this.students }} in your template is never updated?
Jan 10, 2019
11
Level 1
Why isn't data updating?
I'm pretty new to Laravel and Vue, but I can't seem to figure this one out.
app.js:
require('./bootstrap');
import ExampleComponent from './components/ExampleComponent.vue';
window.Vue = require('vue');
const app = new Vue({
el: '#app',
components: {ExampleComponent}
});
ExampleComponent.vue:
<template>
<div class="container">
<h1>Students</h1>
<a href="/students/create" class="btn btn-primary">Add Student</a>
<br /><br />
{{ this.students }}
<ul class="list-group">
<li v-for="student in students" :key="student.id">@{{student}}</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
students: []
}
},
mounted() {
this.fetchStudents();
},
methods: {
fetchStudents() {
console.log('fetch students()', this.students)
axios.get('/index').then((response) => {
console.log(this.students)
this.students = response.data
console.log(this.students)
})
.catch((err) => console.log(err))
}
}
}
</script>
Console when I load the page:
VM4366 app.js:1791 fetch students() [__ob__: Observer]
VM4366 app.js:1793 [__ob__: Observer]
VM4366 app.js:1795 (5) [{…}, {…}, {…}, {…}, {…}, __ob__: Observer]
For whatever reason 'students' is never updating. The request works fine, the data is returned, but I can't get it to update in the component. I'm also not sure what the ___ob___:Observer stuff is. Anybody help?
Please or to participate in this conversation.