0👍
According to your code, you are setting info with the result of axios.get(...)
the result of your REST call is response = { TotalAmount: "2645.09" }
You have several problemes here:
- When you write
then(response => (this.info = response))
info is not equal to the REST call response, but to the object returned by axios. if you want info to be equal to the REST call data, you need to set info withresponse.data
or using object destructuring (then({ data } => (this.info = data))
) - In your template you refer only to
TotalAmount
which is not a known attribut of your component
Update your component like this:
<template>
<div>
<span>{{ totalAmount }}</span>
</div>
</template>
<script>
export default {
data() {
return {
info: undefined,
};
},
async mounted() {
const { data } = await axios.get('https://api_url.php');
this.info = data;
},
computed: {
totalAmount() {
return this.info?.TotalAmount;
},
},
};
</script>
Here I used a computed property totalAmount
in order to avoid error like ‘Cannot read property TotalAmount of undefined’
- [Vuejs]-Adding dynamic meta tags fetched from API to nuxtjs static site
- [Vuejs]-What is the alternative of the code below in react from vue js
Source:stackexchange.com