Created
September 27, 2020 03:56
-
-
Save danangponorogo/0717156f7fb618cf89b8376a31b89281 to your computer and use it in GitHub Desktop.
bertukar data dari respon axios antar komponen
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> | |
export let data; | |
//data = JSON.parse(data); | |
console.log(data); | |
</script> |
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 Dashboard from "./_components/Dashboard.svelte"; | |
import axios from "axios"; | |
import backend from "@danang"; | |
// import { onMount } from "svelte"; | |
// import { createChart } from "../global.svelte"; | |
// onMount(createChart); | |
const url = backend + "/home"; | |
/* | |
axios | |
.get(url, { | |
headers: { | |
Accept: "application/json", | |
}, | |
}) | |
.catch((err) => console.log(err)) | |
.then((res) => getData(res)); | |
*/ | |
let promise = getData(); | |
async function getData() { | |
await axios | |
.get(url, { | |
headers: { | |
Accept: "application/json", | |
}, | |
}) | |
.catch((err) => console.log(err)) | |
.then((res) => { | |
const data = res.data.dashboard[0]; | |
console.log(data); | |
return data; | |
}); | |
/* | |
const res = await fetch(url); | |
const d = await res.text(); | |
*/ | |
} | |
</script> | |
{#await promise} | |
<p>...waiting</p> | |
{:then data} | |
<Dashboard {data} /> | |
{:catch error} | |
<p style="color: red">{error.message}</p> | |
{/await} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment