Last active
January 10, 2022 01:27
-
-
Save shijiezhou1/45b7177081ed08ba752a33a14fe09a0b to your computer and use it in GitHub Desktop.
Vue3 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
<template> | |
<div class="container"> | |
<input | |
type="text" | |
v-model="msg" | |
> | |
<button @click="Create">Create</button> | |
<TodoList | |
:TodoLists="TodoLists" | |
:Delete="Delete" | |
/> | |
</div> | |
</template> | |
<script> | |
import TodoList from './TodoList'; | |
import { ref } from "@vue/runtime-core"; | |
export default { | |
components: { | |
TodoList, | |
}, | |
setup() { | |
let exampleData = [ | |
{ id: 1, name: 'cooking' }, | |
{ id: 2, name: 'eating' }, | |
{ id: 3, name: 'dancing' }, | |
]; | |
const Create = () => { | |
let id = 4; | |
id += 1; | |
const next = { id, name: this.msg }; | |
this.TodoLists.push(next); | |
} | |
const Delete = (idx) => { | |
this.TodoLists = this.TodoLists.filter((r) => r.id !== idx); | |
} | |
return { | |
TodoLists: ref(exampleData), | |
Create, | |
Delete: Delete(idx) | |
}; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment