title: VueJS http get request
body: <p>Trying to send an http get request using Vue js. Can't see any problems with the logic, not too experienced using vuejs though. </p>
  
  <p>Keep getting these two errors:</p>
  
  <blockquote>
    <p>[Vue warn]: Error in mounted hook: "TypeError: Cannot read property
    'get' of undefined"</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'get' of undefined.</p>
  </blockquote>
  
  <pre><code>var owm = new Vue({
    el: '#owm',
    data: {
      debug: true,
      weather: []
    },
    methods: {
      loadWeather: function() {
        this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&amp;type=like&amp;appid=766b78c39446a8fa6313c3b7b2063ade', function(data, status, request){
          if(status == 200)
          {
            this.weather = data;
            console.log(this.weather);
          }
        });
      }
    },
    mounted: function () {
      this.loadWeather();
    }
  });
  </code></pre>
  
  <p>Updated the code using vue resource, the errors are gone but it won't console log any data, what could be wrong?</p>
  
  <pre><code>Vue.use(VueResource);
  var owm = new Vue({
    el: '#owm',
    data: {
      weather: []
    },
    methods: {
      loadWeather: function() {
        this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&amp;type=like&amp;appid=[API KEY]', function(data, status, request){
          if(status == 200)
          {
            this.weather = data;
            console.log(this.weather);
          }
        });
      }
    },
    mounted: function () {
      this.loadWeather();
    }
  });
  </code></pre>
  
  <p>EDIT:
  This code works, don't really understand the .then function though and why the request won't work with the callback function but the .then function does.</p>
  
  <pre><code>this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&amp;type=like&amp;appid=[API KEY]').then((data) =&gt; {
    this.weather = data;
    console.log(this.weather);
  </code></pre>