Skip to content

Instantly share code, notes, and snippets.

@rg3915
Last active March 15, 2023 05:10
Show Gist options
  • Save rg3915/a0e8650d547a4ec3a0cab63ee4c80225 to your computer and use it in GitHub Desktop.
Save rg3915/a0e8650d547a4ec3a0cab63ee4c80225 to your computer and use it in GitHub Desktop.
AlpineJS start project
{
"todos": [
{
"id": 1,
"task": "Learning AlpineJS"
},
{
"id": 2,
"task": "The quick brown fox"
},
{
"id": 3,
"task": "over the lazy dog"
}
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="shortcut icon" href="http://html5-training-in-hyderabad.blogspot.com.br/favicon.ico">
<link rel="shortcut icon" href="https://www.djangoproject.com/favicon.ico">
<link rel="shortcut icon" href="https://alpinejs.dev/favicon.png">
<title>AlpineJS</title>
<!-- Bulma -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<!-- Font-awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Alpine.js -->
<script src="//unpkg.com/alpinejs" defer></script>
</head>
<body>
<div
class="container mt-5"
x-data="getTodos"
>
<table class="table">
<tbody>
<template
x-for="item in items"
:key="item.id"
>
<tr>
<td x-text="item.task"></td>
</tr>
</template>
</tbody>
</table>
</div>
<script src="./main.js"></script>
</body>
</html>
const getTodos = () => ({
items: [],
init() {
this.getData()
},
getData() {
// https://jsonplaceholder.typicode.com/todos
fetch('http://localhost:3000/todos/')
.then(response => response.json())
.then(data => {
this.items = data
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment