Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JillzTom's avatar

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?

0 likes
4 replies
JillzTom's avatar

@thomaskim : How do I install it for Laravel? I'm a bit confused with the configuration provided in the documentation.

thomaskim's avatar
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
riliwanrabo's avatar

If you have Vue-resource installed and still have that issue, make sure your vue-resource.js (or minified) script is below the main vue.js (or minified) script.

Please or to participate in this conversation.