Created
April 27, 2022 23:03
-
-
Save mzaini30/7be5fc1b60bd8081708c2b4c134949d8 to your computer and use it in GitHub Desktop.
Latihan Mengolah REST API dengan Petite Vue
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Document</title> | |
<style> | |
[v-cloak]{ | |
display: none; | |
} | |
</style> | |
<style> | |
* {font-family: Segoe UI;font-size: 1.1rem;} | |
.list {border: .1rem solid #9e9e9e5c;padding: 1rem;box-shadow: 0 0.1rem 0 0 #9e9e9e5c;} | |
.app {gap: 1rem;display: flex;flex-direction: column;} | |
</style> | |
</head> | |
<body> | |
<div class="app" @vue:mounted='init' v-cloak> | |
<div class="list" v-for='x in datanya'>{{ x }}</div> | |
</div> | |
<script type="module"> | |
import {createApp} from './vue.min.js' | |
createApp({ | |
datanya: [], | |
async init(){ | |
let target = 'https://cinnabar.icaksh.my.id/api/public/daily/wiki' | |
target = `https://api.allorigins.win/raw?url=${encodeURIComponent(target)}` | |
let data = await fetch(target) | |
data = await data.json() | |
let kumpulanData = [] | |
for (let x of data.data){ | |
kumpulanData = [...kumpulanData, x.tahukahAnda] | |
} | |
this.datanya = kumpulanData | |
} | |
}).mount('.app') | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment