show price

This commit is contained in:
2023-12-07 04:01:07 +01:00
parent 1f32d0f1f2
commit 52fcf73be0

View File

@@ -1,9 +1,28 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue';
const get = async (url) => {
const response = await fetch(url);
return await response.json();
};
const price = ref();
const fetchPrice = () => {
get('https://blockchain.info/tobtc?currency=USD&value=1').then(res => {
price.value = (1 / res).toFixed(2);
console.log(price.value);
}).finally(err => {
setTimeout(fetchPrice, 15e3);
});
};
fetchPrice();
</script> </script>
<template> <template>
hello 1 BTC = {{ price }} USD
</template> </template>
<style scoped> <style scoped>