Vue 2.1 calling method in beforeCreate hook is not working Vue 2.1 calling method in beforeCreate hook is not working vue.js vue.js

Vue 2.1 calling method in beforeCreate hook is not working


It's because methods hasn't been initialized yet. The easiest way around this it to use the created hook instead:

  created : function() {    this.fetchUsers();  },  methods: {    fetchUsers: function() {      var self = this;      fetch('/assets/data/radfaces.json')        .then(function(response) { return response.json()        .then( function(data) { self.users = data; } );      })        .catch(function(error) {        console.log(error);      });    }  }