I'm trying to fetch data from an API and then display it with vue using the mounted()
method, but when I try it, it says that this
basically is not defined.
I'm not using NodeJS.
<script>
"use strict";
(function() {
var app = new Vue({
el: "#app",
data () {
return {
books: null
}
},
mounted () {
var api = fermata.json("/api/books");
api.get(function(err, res) {
if(res.success) {
this.books = res.result;
}
});
}
});
})();
</script>
Which gives me the following error
Uncaught TypeError: Cannot set property 'books' of undefined