Zeytinburnu masaj Talas masaj Tarsus masaj Tavşanlı masaj Terme masaj Tire masaj Torbalı masaj Toroslar masaj Turgutlu masaj Turgutreis masaj Turhal masaj Tuzla masaj Ulus masaj Ümraniye masaj Urla masaj Üsküdar masaj Vezirköprü masaj Viranşehir masaj Yatağan masaj Yenimahalle masaj Yenişehir masaj Yıldırım masaj Yomra masaj Yumurtalık masaj Yunusemre masaj Yüreğir masaj escort bayan İstanbul escort İzmir escort Kahramanmaraş escort Kastamonu escort Kayseri escort Kıbrıs escort Kırklareli escort Kocaeli escort Konya escort Kütahya escort Erbaa escort Erdemli escort Ereğli escort Erenler escort Ergene escort Esenler escort Esenyurt escort Eskil escort Espiye escort Eyüpsultan escort Eyyübiye escort Fatih escort Fatsa escort Fethiye escort Finike escort Gaziemir escort Gaziosmanpaşa escort Gazipaşa escort Gebze escort Gediz escort Gelibolu escort Gemerek escort Gemlik escort Geyve escort Gölcük escort Gönen escort Görükle escort Güllük escort Gümbet escort Gümüşlük escort Güngören escort Gürsu escort Haliliye escort Hendek escort Horasan escort Ilgın escort İlkadım escort İncirliova escort İnegöl escort İskenderun escort İzmit escort İznik escort Kadirli escort Kadıköy escort Kadınhanı escort Kağıthane escort Kahramankazan escort Kangal escort Kapaklı escort Karabağlar escort bursa escort bursa escort istanbul escort denizli escort düzce escort malatya escort erzincan escort zonguldak escort eskişehir escort gaziantep escort gaziantep escort gümüşhane escort hatay escort hatay escort ığdır escort gaziantep escort istanbul escort konya escort izmit escort kars escort escort adana escort bayan adıyaman escort bayan afyon escort bayan ağrı escort bayan aksaray escort bayan amasya escort bayan antalya escort bayan ankara escort bayan ardahan escort bayan artvin escort bayan aydın escort bayan balıkesir escort bayan bartın escort bayan batman escort bayan bayburt escort bayan bilecik escort bayan bingöl escort bayan bitlis escort bayan bolu escort bayan burdur escort bayan bursa escort bayan Çanakkale escort bayan Çankırı escort bayan Çorum escort bayan denizli escort bayan diyarbakır escort bayan düzce escort bayan edirne escort bayan elazığ escort bayan sivas escort bayan sinop escort bayan urfa escort samsun escort bayan sakarya escort bayan rize escort bayan osmaniye escort bayan ordu escort bayan niğde escort bayan nevşehir escort bayan muş escort bayan muğla escort bayan mersin escort bayan mardin escort bayan manisa escort bayan malatya escort bayan kütahya escort bayan konya escort bayan kocaeli escort bayan kırşehir escort bayan kırklareli escort bayan kırıkkale escort bayan kilis escort bayan kıbrıs escort bayan kayseri escort bayan kastamonu escort bayan kars escort bayan karaman escort bayan karabük escort bayan maraş escort izmit escort bayan izmir escort bayan istanbul escort bayan Isparta escort bayan Iğdır escort bayan hatay escort bayan hakkari escort bayan gümüşhane escort bayan giresun escort bayan gaziantep escort bayan eskişehir escort bayan erzurum escort bayan erzincan escort bayan tekirdağ escort bayan tokat escort bayan trabzon escort bayan uşak escort bayan van escort bayan yalova escort bayan yozgat escort bayan zonguldak escort bayan

windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

Vue axios get http not returning the response data

Asked By: Anonymous

I have data.js importing axios and VueAxios as below:

When I am calling the getRecordTypes function in mutations(vuex) returns undefined. But when I do console log it returns the correct data set.

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

let BASE_URL = 'http://localhost:3000'
const API_URL = `${BASE_URL}/api/v1/`

export default {
  getRecordTypes () {
    let results = []
    let url = `${API_URL}record_types`
    axios.get(url).then((response) => {
      console.log(response.data) // return the actual arrary of data
      results = response.data
      return results
    }).catch(error => { console.log(error) })
  }
}

In my vuex mutations js file, I have imported the above data.js file like below:

import data from '@/lib/api/data'

export default {
  setRecordTypes (state) {
    console.log(data.getRecordTypes())  // return undefined
    state.recordTypes = data.getRecordTypes()
  }
}

I am new to Vue js and not sure what am I doing wrong?

Thanks in advance


Solution

Answered By: Anonymous

getRecordTypes() did’t return anything, also is async function, actually return a Promise object.

All methods of axios return Promise object, rather than a direct result of response. If you understand the basics of async and Promise first, this will make learning easier 🙂

// data.js
export default {
  getRecordTypes () {
    let url = `${API_URL}record_types`
    // add return
    return axios.get(url).then((response) => {
      console.log(response.data) // return the actual arrary of data
      results = response.data
      return results
    }).catch(error => { console.log(error) })
  }
}

// mutations.js
import data from '@/lib/api/data'

export default {
  setRecordTypes (state) {
    // async
    data.getRecordTypes().then(results => {
      state.recordTypes = results
    })
  }
}

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno
Alanya escort Manavgat escort Fethiye escort Kemer escort Didim escort http://www.kadinescort.net Gaziantep escort Denizli escort Adana escort Hatay escort Aydın escort İzmir escort Ankara escort Antalya escort Bursa escort İstanbul escort Kocaeli escort Konya escort Muğla escort Malatya escort Kayseri escort Mersin escort Samsun escort Sinop escort Tekirdağ escort Eskişehir escort Yalova escort Rize escort Amasya escort Balıkesir escort Çanakkale escort Bolu escort Erzincan escort Şırnak escort Van escort Yozgat escort Zonguldak escort Afyon escort Adıyaman escort Bilecik escort Aksaray escort Ağri escort Bitlis escort Siirt escort Çorum escort Burdur escort Diyarbakir escort Edirne escort Düzce escort Erzurum escort Kırklareli escort Giresun escort Kilis escort Kars escort Karabük escort Kırıkkale escort Mardin escort Kırşehir escort Maraş escort Manisa escort Muş escort Kastamonu escort Ordu escort Nevşehir escort Sakarya escort Osmaniye escort Şanliurfa escort Sivas escort Trabzon escort Tokat escort Ardahan escort Bartın escort Karaman escort Batman escort Bayburt escort Bingöl escort Elaziğ escort Gümüşhane escort Hakkari escort Isparta escort Uşak escort Igdır escort