I am trying to set the value of a prop in vue JS to the output of a function I have in another class. However when I call this function, the actual code of the function is returned instead of the output of that function. Here is the code that I have along with the screenshot of what I am referring to.
Within my template
<nav>
<ul>
<li><router-link to="/games">All Games</router-link></li>
<li><modal-deposit>Deposit</modal-deposit></li>
<li @click="logout"><router-link to="/">Logout</router-link></li>
<li>Balance {{ updateBalance }} </li>
</ul>
</nav>
Within export default
computed: {
updateBalance: function(){
return WalletService.getBalance;
}
}
Within WalletService.js
class WalletService{
//Get the balance from our logged in wallet
static getBalance(){
axios.get(url + decoded.email).then((res)=> {
console.log(res.data[0].balance);
return res.data[0].balance;
})
}
}
I want the value from res.data[0].balance, but I am not sure why it is returning the actual code. I would like to add that I am still learning vuejs and have not used any reactive frameworks prior to this. I have tried using watch: instead of computed: but this breaks the prop value stating that it is referenced during render, but not defined. Even when I declare it in the data() section of export default.
