S
S
streetn12019-01-14 17:43:56
JavaScript
streetn1, 2019-01-14 17:43:56

How to work with asynchronous data?

Hello. I ran into a problem with processing the data that I receive through an ajax request. The essence of the problem is that I do not understand how json should be processed. Because js always throws 'undefined properties'.
1) In Vuex, I created an action that receives json:

SET_RATING: async (context, payload) => {
  let data = await Axios.get('https://r-volsu.ru/api/rating/ИВТм-181');
  context.commit('SET_RATING', data.data);
}

2) I'm trying to process the incoming data in the component:
computed:{
  semester(){
     let result = this.$store.getters.RATING.rating; // тут json все нормально
     let current = this.$store.getters.RATING.currentSemester; // "Первый семестр"

     result[current] // вот тут и получаю undefined properties
  }
}

How to act in such situations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leo Developer, 2019-01-14
@crazy_leo

What is your JSON format? Is it just a string or already parsed JSON as an object?
If this is a string, then you need to parse -const data = JSON.parse(jsonData)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question