An even more educational version of the Bandolier for Learn JS the Hard Way.
https://learnjsthehardway.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
9 months ago
|
{% include "./header.html" %}
|
||
|
<h1>Your TODOs</h1>
|
||
|
|
||
|
<script src="/alpine.js"></script>
|
||
|
|
||
|
<script>
|
||
|
const new_task = async (todos, task) => {
|
||
9 months ago
|
const result = await axios({
|
||
|
method: "post",
|
||
|
url: "/todo_alpine",
|
||
|
data: {task},
|
||
|
headers: {
|
||
|
Accept: "application/json"
|
||
|
}
|
||
|
});
|
||
|
|
||
9 months ago
|
// zero error handling but fine for now
|
||
9 months ago
|
return result.data;
|
||
|
}
|
||
|
|
||
|
const list_todo = async () => {
|
||
|
const result = await axios({
|
||
|
method: "get",
|
||
|
url: "/todo_alpine",
|
||
|
headers: {
|
||
|
Accept: "application/json"
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return result.data;
|
||
9 months ago
|
}
|
||
|
</script>
|
||
|
|
||
|
<p>Welcome {{ name }}, here's your TODOs</p>
|
||
|
|
||
|
<div
|
||
|
x-data="{todos: []}"
|
||
9 months ago
|
x-init="todos = await list_todo()">
|
||
9 months ago
|
<ol>
|
||
|
<template x-for="todo of todos">
|
||
|
<li x-text="todo.task"></li>
|
||
|
</template>
|
||
|
</ol>
|
||
|
|
||
|
<h4>Add a New TODO</h4>
|
||
9 months ago
|
<form action="/todo_alpine" @submit.prevent="todos = await new_task(todos, task), task = ''" method="POST" x-data="{task: ''}">
|
||
9 months ago
|
<label for="task">Task</label>
|
||
|
<input name="task" x-model="task"></input>
|
||
9 months ago
|
<button type="button" @click="todos = await new_task(todos, task), task = ''">Submit</button>
|
||
9 months ago
|
</form>
|
||
|
|
||
|
</div>
|
||
|
{% include "./footer.html" %}
|