Created
March 23, 2021 13:13
-
-
Save penalosa/61443cd29eb18f262fee795b4b2fabd5 to your computer and use it in GitHub Desktop.
Data fetching in Svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import { onMount } from "svelte" | |
let data | |
onMount(() => { | |
fetch("https://example.com/my/api") | |
.then(r => r.json()) | |
.then(j => data = j) | |
} | |
</script> | |
{data} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment