0

I'm using vue-resource in index.js, also I have installed package. But $http.get not working.

import Vue from 'vue'
import Router from 'vue-router'
import VueResource from 'vue-resource'
import HelloWorld from '@/components/HelloWorld'

Vue.use(VueResource)
Vue.use(Router)

export default new Router({
 routes: [
  { 
   path: '/',
   name: 'HelloWorld',
   component: HelloWorld
 }
]})

HelloWorld.vue

created: () => {
  console.log('run');
  this.$http.get('https://jsonplaceholder.typicode.com/posts')
    .then((response) => {
      this.posts = response.data;
      console.log(this.newUser);
    });
}

vuejs

  • 1
    Do not use an arrow function to define `created`. – Bert Jun 30 '18 at 13:39
  • @Bert Thank you buddy! Why vue not understand arrow function? –  Jun 30 '18 at 14:23
  • It's not that Vue doesn't understand arrow functions, the problem with using an arrow function define `this` as the context in which the arrow function is defined, which, before the component is created, is *not* the component. – Bert Jun 30 '18 at 15:26
  • Thank you Bert... –  Jun 30 '18 at 15:31

0 Answers0