Skip to content

Instantly share code, notes, and snippets.

@shijiezhou1
Last active January 10, 2022 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shijiezhou1/45b7177081ed08ba752a33a14fe09a0b to your computer and use it in GitHub Desktop.
Save shijiezhou1/45b7177081ed08ba752a33a14fe09a0b to your computer and use it in GitHub Desktop.
Vue3 Todo
<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