I'm trying to make a simple converter, that is, the user inputs the amount and the price gets converted. Suppose I have an input field on my website:
<input type="number" v-model="coin_amount" id="usd" placeholder="Amount (USD)">
And convert() function that converts coin_amount to another currency
convert() {
axios({
method: "GET",
"url": "https://api.coinmarketcap.com/v1/ticker/" + this.input.cryptocurrency + "/"
}).then(result => {
this.coin_amount = this.coin_amount / result.data[0].price_usd;
}, error => {
console.error(error);
});
return this.coin_amount;
}
And i display the converted value like this:
<span><strong>Value:</strong> {{ coin_amount }}</span>
How can I invoke the convert() function so that it can convert the amount while typing (LIVE). I thought to use v-model but it just shows the inputted amount, not the converted one. I also thought to use a special convert button and invoke it with v-on:click="convert() but I want to make it more advanced.