vue3-core/playground/src/todo-mvc.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.2 KiB
Vue
Raw Normal View History

<script setup lang="ts">
2024-01-20 23:48:10 +08:00
import { onMounted, ref } from 'vue/vapor'
interface Task {
title: string
completed: boolean
}
const tasks = ref<Task[]>([])
2024-01-20 13:38:20 +08:00
const value = ref('hello')
2024-01-20 23:48:10 +08:00
const inputRef = ref<HTMLInputElement>()
2024-01-20 13:38:20 +08:00
function handleAdd() {
tasks.value.push({
title: value.value,
completed: false,
})
// TODO: clear input
value.value = ''
}
2024-01-20 23:48:10 +08:00
onMounted(() => {
console.log('onMounted')
console.log(inputRef.value)
})
</script>
2024-01-20 13:38:20 +08:00
<template>
<ul>
<!-- TODO: v-for -->
<li>
<!-- TODO checked=false -->
<input type="checkbox" :checked="tasks[0]?.completed" />
{{ tasks[0]?.title }}
</li>
<li>
<input type="checkbox" :checked="tasks[1]?.completed" />
{{ tasks[1]?.title }}
</li>
<li>
<input type="checkbox" :checked="tasks[2]?.completed" />
{{ tasks[2]?.title }}
</li>
<li>
<input type="checkbox" :checked="tasks[3]?.completed" />
{{ tasks[3]?.title }}
</li>
<li>
<input
type="text"
2024-01-20 23:48:10 +08:00
:ref="el => (inputRef = el)"
2024-01-20 13:38:20 +08:00
:value="value"
@input="evt => (value = evt.target.value)"
/>
<button @click="handleAdd">Add</button>
</li>
</ul>
</template>