Last active
January 4, 2022 11:19
-
-
Save JeffreyWay/4860d1fcf1bfcaf8b24e78ec350f9658 to your computer and use it in GitHub Desktop.
How and When to Extract Alpine Component Logic - https://laracasts.com/series/alpine-essentials/episodes/5
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"> | |
<title>Alpine Examples</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" | |
> | |
</head> | |
<body class="p-10 max-w-lg mx-auto"> | |
<div class="bg-gray-300 px-10 py-6 rounded" | |
x-data="taskApp()" | |
> | |
<form @submit.prevent="submit"> | |
<input type="text" | |
placeholder="Go to the market..." | |
x-model="newTask" | |
class="w-full px-1" | |
> | |
</form> | |
<ul class="list-disc mt-3"> | |
<template x-for="(task, index) in tasks" | |
:key="index" | |
> | |
<li> | |
<input type="checkbox" x-model="task.completed"> | |
<span x-text="task.body" :class="{ 'line-through' : task.completed }"></span> | |
</li> | |
</template> | |
</ul> | |
</div> | |
</body> | |
<script> | |
let taskApp = () => { | |
return { | |
tasks: [], | |
newTask: '', | |
submit() { | |
this.tasks.push({ body: this.newTask, completed: false }); | |
this.newTask = ''; | |
} | |
}; | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment