Hi I am trying to get information from the controller with the async function and I do this in the component:
I need to send the parameters, because I have seen similar answers with mounted() but they do not send parameters to the function so if I do not add parameters it will not work.
View part:
<tbody>
<tr v-for="(post, index) in last_month_day" v-bind:index="index">
<td>{{ index+1 }}</td>
<td v-for="(post2, index2) in branch_office_posts" v-bind:index="index2">
$ {{ getTotalIncomes(index+1, post2.branch_office_id) }}
</td>
</tr>
</tbody>
I need to pass those two parameters to the function: index+1 and post2.branch_office_id
Then I do this in the method part:
methods: {
async TotalIncomeData(day, branch_office_id) {
const response = await fetch('/api/collection/total/'+day+'/'+branch_office_id+'?api_token='+App.apiToken)
return response;
},
getTotalIncomes(day, branch_office_id) {
return this.TotalIncomeData(day, branch_office_id);
},
It works I mean if check the response with console.log() It gets a value. I know that I can not use the async await function in the view, that's why I use another function to call this one inside how you can see BUT I do not know why I am not using it directly to the view and it says this:
$ [object Promise]
So It does not show the value, so I wonder why? what is wrong in the code? I really need a HELP Thanks!
.then()to handle the result