dimanche 9 juillet 2017

how can i access vuejs data in method

i have saved a collection of data from database to an array in vue js using ajax request in laravel. i want to get some data from that collection inside a method so that i can make more data for the body but somehow i cant access it. for example, by using the code below.

var vm = this;
$.get('url', function (response) {
      vm.time_slots = response;
     }, 'json');
     console.log(vm.time_slots[0]);

i get undifined. but if i access it through the console i get what i need. below is the data.

data: {
            time_slots: [],
            current_timeslots: []
        },

now each time_slot in time_slots has a start_date end_date etc. i want to access them but i get undefined. even this.time_slots.length is returned as 0, while if i check in console i get 12. how can i access data with in the method.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u68sp0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire