Created
September 10, 2020 21:28
-
-
Save javedbaloch4/c33e2a1b87246594e5949f9c9d12ceb9 to your computer and use it in GitHub Desktop.
AlpineJS fetch & init example using Kanye.rest API.
This file contains hidden or 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"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Home</title> | |
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script> | |
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet"> | |
<link rel="stylesheet" href=""> | |
</head> | |
<body class="bg-gray-400 text-gray-800"> | |
<div | |
class="container mx-auto px-4" | |
x-data="{ quote: '' }" | |
x-init=" | |
fetch('https://api.kanye.rest') | |
.then(response => response.json()) | |
.then(data => quote = data.quote) | |
" | |
> | |
<div class="flex items-center text-center justify-center h-screen text-2xl italic" x-text="`"${quote}"`"></div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment