0π
β
- The
ready
hook is for Vue 1. In version 2 you need to use eithercreated
ormounted
. - Instead of using
this.$set
, you should declaremovies
upfront in the data object. - Are you using vue-resource? I think your
this.$http.get
call may be incorrect; I donβt think it accepts a callback, it returns a Promise. Also the function is not bound tothis
which may be a problem (use arrow function syntax instead).
Modified for Vue 2:
new Vue({
el: '#app',
data: {
movies: [],
},
mounted() {
this.getMovies();
},
methods: {
getMovies() {
this.$http.get(apiURL).then(res => {
this.movies = res.data;
});
}
}
})
Otherwise if youβre using Vue 1 then just keep ready
as-is.
Source:stackexchange.com