Async request

This commit is contained in:
Matthis FAUVET 2024-06-21 00:21:46 +02:00
parent fd128da2e4
commit 40043f0293
3 changed files with 16 additions and 9 deletions

View File

@ -4,8 +4,9 @@
<meta charset="utf-8">
<title>Riot App</title>
<script src="https://cdn.tailwindcss.com"></script>
<script type="javascript" src="model.js"></script>
</head>
<body>
<body class="bg-neutral-50">
<onzer></onzer>
@ -13,10 +14,11 @@
<script src="https://unpkg.com/riot@9/riot+compiler.min.js"></script>
<script type="riot" src="./onzer.riot"></script>
<script type="javascript" src="./onzer.riot"></script>
<script type="text/javascript">
riot.compile().then(() => {
riot.mount('onzer')
riot.mount('onzer');
})
</script>

5
model.js Normal file
View File

@ -0,0 +1,5 @@
function getSongs(){
return fetch(`https://dwarves.iut-fbleau.fr/~fauvet/api/songs`).then(response => {
return response;
})
}

View File

@ -16,15 +16,16 @@
<script>
export default {
onBeforeMount(e){
async onBeforeMount(props){
const response = await fetch('https://dwarves.iut-fbleau.fr/~fauvet/api/songs');
console.log(response);
this.state.placeholder = "Rechercher dans les albums";
console.log(this.state.items);
},
edit(e) {
e.preventDefault()
this.state = {items: [{item: "caca", size: 23}, {item: "aze", size: 3}]};
this.state.name = "Gros caca";
console.log(this.state)
this.update();
},
click(e) {
e.preventDefault();
@ -42,5 +43,4 @@
}
}
</script>
</onzer>