@jillztom Did you install vue-resource?
Sep 15, 2015
4
Level 10
Error in Vue.js data fetching
I'm trying to get the data from the server via api in my Vue.js instance as below:
methods: {
addDonation: function(backer){
this.backers.push(backer);
},
alertUser: function(backer){
this.notifications.push({ title: 'New Donation', date: '3 mins ago', msg: 'World Vision - Brooklyn, NYC, US' });
},
fetchNotifications: function() {
this.$http.get('/api/v1/notifications?uid='+$('meta[name="uid"]').attr('content')).success(function(events) {
this.$set('notifications', events);
}).error(function(error) {
console.log(error);
});
}
}
But I'm getting an error as follows:
Uncaught TypeError: Cannot read property 'get' of undefined
How can I solve this?
Level 41
@jillztom How did you install vue? Did you use npm for that? If so, just go to your command line interface and install vue-resouce with this command:
npm install vue-resource --save
Then, you just add these lines to your code:
var Vue = require('vue');
Vue.use(require('vue-resource'));
2 likes
Please or to participate in this conversation.