Answer the question
In order to leave comments, you need to log in
How can I display the current exchange rate on vue?
How can I display the current exchange rate on vue.js?
Is there an example of how to contact via api?
<div id="USD">Доллар США $ — 00,0000 руб.</div>
<div id="EUR">Евро € — 00,0000 руб.</div>
<script>
function CBR_XML_Daily_Ru(rates) {
function trend(current, previous) {
if (current > previous) return ' ▲';
if (current < previous) return ' ▼';
return '';
}
var USDrate = rates.Valute.USD.Value.toFixed(4).replace('.', ',');
var USD = document.getElementById('USD');
USD.innerHTML = USD.innerHTML.replace('00,0000', USDrate);
USD.innerHTML += trend(rates.Valute.USD.Value, rates.Valute.USD.Previous);
var EURrate = rates.Valute.EUR.Value.toFixed(4).replace('.', ',');
var EUR = document.getElementById('EUR');
EUR.innerHTML = EUR.innerHTML.replace('00,0000', EURrate);
EUR.innerHTML += trend(rates.Valute.EUR.Value, rates.Valute.EUR.Previous);
}
</script>
<script src="//www.cbr-xml-daily.ru/daily_jsonp.js" async></script>
Answer the question
In order to leave comments, you need to log in
In mounted, we define the handling of the getrates event, and we pull it from outside, because we also define the CBR_XML_Daily_Ru function, in it we pull the getrates event. You can create a global EventBus, or you can use the current instance of the component.
Example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question