Vue
HTML
<div id="app">
<template v-if="rates">
<div id="USD">Доллар США $ — {{getDollar}} руб.</div>
<div id="EUR">Евро € — {{getEuro}} руб.</div>
</template>
</div>
<script>
var app = new Vue({
el: "#app",
data: {
rates: null
},
mounted() {
this.$on('getrates', (rates) => {
this.rates = rates;
})
},
computed: {
getDollar() {
return this.rates.Valute.USD.Value.toFixed(4).replace('.', ',');
},
getEuro() {
return this.rates.Valute.EUR.Value.toFixed(4).replace('.', ',');
}
}
});
function CBR_XML_Daily_Ru(rates) {
app.$emit('getrates', rates);
}
</script>
<script src="//www.cbr-xml-daily.ru/daily_jsonp.js"></script>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}