I am trying to get Multiple API URLs call in Vue.
I tried a single API URL call, and it worked. When I tried to use multiple calls, it did not work.
And it worked for the following:
async asyncData({ $axios }) {
let { data } = await $axios.$get("/Userslist");
return {
Userslist: data,
};
},
computed: {
UserCount () {
return Object.keys(this.Userslist).length;
},
}
<p>{{ UserCount }}</p>
But not this:
async asyncData({ $axios }) {
let { Usersdata } = await $axios.$get("/Userslist");
return {
Userslist: Usersdata ,
};
},
computed: {
UserCount () {
return Object.keys(this.Userslist).length;
},
}
<p>{{ UserCount }}</p>
My multiple API URL call code:
<p>{{ UserCount }}</p>
<p>{{ BusinessCount}}</p>
<script>
import axios from "axios";
export default {
data() {
return {
Userslist: [],
Businesslist: [],
};
},
async asyncData({ $axios }) {
let { dataBusiness } = await $axios.$get("/Businessregisterlist");
let { dataUsers } = await $axios.$get("/Userslist");
return {
Businesslist: dataBusiness,
Userslist: dataUsers,
};
},
computed: {
BusinessCount() {
return Object.keys(this.Businesslist).length;
},
UserCount() {
return Object.keys(this.Userslist).length;
},
},
}
</script>
I'm getting this error:
I tried to console.log
it: