|
|
|
@ -5,8 +5,29 @@ |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
const new_task = async (todos, task) => { |
|
|
|
|
const result = await axios({ |
|
|
|
|
method: "post", |
|
|
|
|
url: "/todo_alpine", |
|
|
|
|
data: {task}, |
|
|
|
|
headers: { |
|
|
|
|
Accept: "application/json" |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// zero error handling but fine for now |
|
|
|
|
return (await axios.post("/todo_alpine", {task})).data; |
|
|
|
|
return result.data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const list_todo = async () => { |
|
|
|
|
const result = await axios({ |
|
|
|
|
method: "get", |
|
|
|
|
url: "/todo_alpine", |
|
|
|
|
headers: { |
|
|
|
|
Accept: "application/json" |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return result.data; |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
@ -14,7 +35,7 @@ |
|
|
|
|
|
|
|
|
|
<div |
|
|
|
|
x-data="{todos: []}" |
|
|
|
|
x-init="todos = (await axios.get('/todo_alpine')).data"> |
|
|
|
|
x-init="todos = await list_todo()"> |
|
|
|
|
<ol> |
|
|
|
|
<template x-for="todo of todos"> |
|
|
|
|
<li x-text="todo.task"></li> |
|
|
|
@ -22,10 +43,10 @@ |
|
|
|
|
</ol> |
|
|
|
|
|
|
|
|
|
<h4>Add a New TODO</h4> |
|
|
|
|
<form action="/todo_index" @submit.prevent="todos = new_task(todos, task), task = ''" method="POST" x-data="{task: ''}"> |
|
|
|
|
<form action="/todo_alpine" @submit.prevent="todos = await new_task(todos, task), task = ''" method="POST" x-data="{task: ''}"> |
|
|
|
|
<label for="task">Task</label> |
|
|
|
|
<input name="task" x-model="task"></input> |
|
|
|
|
<button type="button" @click="todos = new_task(todos, task), task = ''">Submit</button> |
|
|
|
|
<button type="button" @click="todos = await new_task(todos, task), task = ''">Submit</button> |
|
|
|
|
</form> |
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
|