3 years ago

vue resource problem with get

Posted 3 years ago by NightM4re

Hi everyone, this is my first post here in Laracast and I am so exiting learning laravel with vue.js. I am trying to make ajax request with vue resource but I have some problem. I hope you can help me to solve this because I really want to use this plugin. Here is my error " main.js:14 Uncaught TypeError: Cannot read property 'get' of undefined "

And my code is in

Vue.config.debug = true; Vue.config.devtools = true;

var urlAPI = ''; new Vue({ el: '#app',

created: function() { this.consultarAPI(); },

methods: { consultarAPI: function(){ this.$http.get(urlAPI).then(function (response){ console.log('Bien'); }, function(response) { console.log('Mal'); }); } } });

and my code in index.html

<div class="container" style="margin-top:100px;">
    <div id="app">
          <div class="row">
            <div class="col s12 m2 l3"><p></p></div>
            <div class="col s12 m8 l6">
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat eius consectetur aspernatur doloribus libero modi, facere culpa! Tenetur soluta omnis perferendis ipsa esse, voluptates excepturi repellendus aperiam corporis vel vitae?
            <div class="col s12 m2 l3"></div>

And when I try to use the normal call

methods: { consultarAPI: function(){ this.$http({url: urlAPI, method: 'GET'}).then(function (response){ console.log('Bien'); }, function(response) { console.log('Mal'); }); } }

I receive this message

"main.js:14 Uncaught TypeError: this.$http is not a function"

Thanks so much for help me.

Please sign in or create an account to participate in this conversation.