Created
April 17, 2020 23:46
-
-
Save jpalala/ff28bbea346ba3f4dd086cdfc28e0c06 to your computer and use it in GitHub Desktop.
svelte-todo
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
<script> | |
let todos = []; | |
function addTodo() { | |
todos = [...todos, '']; | |
} | |
function removeSelf(index) { | |
todos = [...todos.slice(0, index), ...todos.slice(index + 1)] | |
} | |
</script> | |
{#each todos as todo, index} | |
<input bind:value={todos[index]}> | |
<button on:click={() => removeSelf(index)}>✗</button> | |
<br> | |
{/each} | |
<button on:click{addTodo}>Add</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment