K
K
Krivetko832021-02-17 17:00:49
Vue.js
Krivetko83, 2021-02-17 17:00:49

On the [object Promise] page in the console, the value is correct, why and how to fix it?

Hello: I broke my whole head, tell me pliz, I place a button on the page:

<v-btn fab color="#00C3EA" top right absolute class="white--text">
                                {{ getRating(tutor) }}
 </v-btn>

Here is the function:
async getRating(tutor) {
          let rating=0
          let lang = ''
          if (!this.language) {
             lang = this.$route.query.lang
          } else {
             lang = this.language
          }
          const rat = await this.$axios.$post('/tutors/getTutorRating.php', '{"tutor_id": '+tutor.id+', "lang": "'+lang+'"}').then((responce)=>{
            rating = responce.average_rating
          })
          console.log(rating)
          return rating
        },


As a result, I see the correct value in the console (for example, 3.6) and on the page the inscription [object Promise]

Tell me how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2021-02-17
@wapster92

write rating in data and change the value in your function, and run the function on a click event

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question