|
@@ -1,30 +1,68 @@
|
|
|
<template>
|
|
|
- <h2>响应式数据的判断</h2>
|
|
|
+ <div class="todo-container">
|
|
|
+ <div class="todo-wrap">
|
|
|
+ <Header :addTodo="addTodo"></Header>
|
|
|
+ <List :todos="todos"></List>
|
|
|
+ <Footer></Footer>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import { defineComponent ,ref,isRef, isReactive, reactive, isReadonly, readonly, isProxy} from 'vue'
|
|
|
-
|
|
|
+import { defineComponent, reactive, toRefs } from "vue";
|
|
|
+//引入子级组件
|
|
|
+import Header from "./components/Header.vue";
|
|
|
+import List from "./components/List.vue";
|
|
|
+import Footer from "./components/Footer.vue";
|
|
|
+import { Todo } from "./types/todo";
|
|
|
export default defineComponent({
|
|
|
- //isRef
|
|
|
- //isReactive
|
|
|
- //isReadonly
|
|
|
- //isProxy
|
|
|
- setup () {
|
|
|
- //isRef: 检查一个值是否为ref对象
|
|
|
- console.log(isRef(ref({})))
|
|
|
- //isReactive检查一个对象是否是reactive创建的响应式代理
|
|
|
- console.log(isReactive(reactive({})))
|
|
|
- //isReadonly 检查一个对象是否是由readonly创建的只读代理
|
|
|
- console.log(isReadonly(readonly({})))
|
|
|
- //isProxy 检查一个对象是否是由reactive或者readonly方法创建的代理
|
|
|
- console.log(isProxy(readonly({})))
|
|
|
- console.log(isProxy(reactive({})))
|
|
|
- return {}
|
|
|
- }
|
|
|
-})
|
|
|
+ setup() {
|
|
|
+ //定义一个数组数据 存放每一个对象 对象下面{id,title,isCompleted}
|
|
|
+ const state = reactive<{ todos: Todo[] }>({
|
|
|
+ todos: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ title: "奔驰",
|
|
|
+ isCompleted: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ title: "宝马",
|
|
|
+ isCompleted: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 3,
|
|
|
+ title: "奥迪",
|
|
|
+ isCompleted: false,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+
|
|
|
+ //添加数据的方法
|
|
|
+ const addTodo = (todo: Todo) => {
|
|
|
+ state.todos.unshift(todo);
|
|
|
+ };
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ addTodo,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ components: {
|
|
|
+ Header,
|
|
|
+ List,
|
|
|
+ Footer,
|
|
|
+ },
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
-
|
|
|
+.todo-container {
|
|
|
+ width: 600px;
|
|
|
+ margin: 0 auto;
|
|
|
+}
|
|
|
+.todo-container .todo-wrap {
|
|
|
+ padding: 10px;
|
|
|
+ border: 1px solid #ddd;
|
|
|
+ border-radius: 5px;
|
|
|
+}
|
|
|
</style>
|