json-server -w db.json
Port 3000
Or https://jsonplaceholder.typicode.com/todos
http-server
Port 8080
Ref: alpinejs/alpine#520
json-server -w db.json
Port 3000
Or https://jsonplaceholder.typicode.com/todos
http-server
Port 8080
Ref: alpinejs/alpine#520
| { | |
| "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 | |
| }) | |
| } | |
| }) |