mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
429 B
24 lines
429 B
6 years ago
|
<script>
|
||
|
async function getRandomNumber() {
|
||
3 years ago
|
const res = await fetch(`/tutorial/random-number`);
|
||
6 years ago
|
const text = await res.text();
|
||
|
|
||
|
if (res.ok) {
|
||
|
return text;
|
||
|
} else {
|
||
|
throw new Error(text);
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
let promise = getRandomNumber();
|
||
|
|
||
6 years ago
|
function handleClick() {
|
||
|
promise = getRandomNumber();
|
||
|
}
|
||
|
</script>
|
||
|
|
||
1 year ago
|
<button on:click={handleClick}> generate random number </button>
|
||
6 years ago
|
|
||
|
<!-- replace this element -->
|
||
4 years ago
|
<p>{promise}</p>
|