+
+ count: {{ counter.count }}
+
+
+
+
+
+
+~~~
+#### 4.变更
+用 store.count++ 直接改变 store,还可以调用 $patch 方法
+#### 5.替换
+不能完全替换掉 store 的 state,因为那样会破坏其响应性,还是使用patch
+
+### 四、Getter
+Getter 完全等同于 store 的 state 的计算属性
+~~~js
+export const useCountStore = defineStore('count',{
+ state:()=>{
+ return {count:1}
+ },
+ actions:{
+ onClick(){
+ this.count++
+ }
+ },
+ getters: {
+ doubleCount: (state) => state.count * 2,
+ },
+})
+~~~
+- 大多数时候,getter 仅依赖 state,不过,有时它们也可能会使用其他 getter,通过 this,你可以访问到其他任何 getter
+- getter 只是幕后的计算属性,所以不可以向它们传递任何参数。不过,你可以从 getter 返回一个函数,该函数可以接受任意参数
+~~~js
+export const useUsersStore = defineStore('users', {
+ getters: {
+ getUserById: (state) => {
+ // 可以返回函数,这个返回的函数可以接受容易参数
+ return (userId) => state.users.find((user) => user.id === userId)
+ },
+ },
+})
+ // 调用
+
+~~~
+
+### 五、Action
+Action 相当于组件中的方法,也可通过 this 访问整个 store 实例,而且是可以异步的
\ No newline at end of file
diff --git "a/\346\236\227\346\230\245\347\277\224/20240516_\350\267\257\347\224\261\345\272\224\347\224\250.md" "b/\346\236\227\346\230\245\347\277\224/20240516_\350\267\257\347\224\261\345\272\224\347\224\250.md"
new file mode 100644
index 0000000..4da751f
--- /dev/null
+++ "b/\346\236\227\346\230\245\347\277\224/20240516_\350\267\257\347\224\261\345\272\224\347\224\250.md"
@@ -0,0 +1,34 @@
+### 通过路由方式实现增删改查
+#### 思路:
+1. 配置路由:
+~~~js
+// src/router/router.js
+ import { createRouter, createWebHistory } from 'vue-router';
+ import Home from './components/Home.vue';
+ import ManageItem from './components/Edit.vue';
+ const router = createRouter({
+ history: createWebHistory(),
+ routes:[
+ {path:'/home',component:Home},
+ { path: '/edit/:id?',
+ name: 'Edit',
+ component: Edit,
+ },
+ {path:'/',component:App},
+ // 这里也可以加上redirect:'/home' 表示一打开就跳转到列表页,但是不推荐
+ ]
+ } );
+ export default router;
+~~~
+2. 配置入口文件:
+~~~js
+ import router from '.Router/router';
+ const app = createApp(App);
+ app.use(router);
+~~~
+3. 创建视图组件:Home.vue(列表页面)、Edit.vue(新增编辑页)、
+ - 列表页部分代码如下:
+ - 
+
+ - 编辑页部分代码如下:
+ - 
\ No newline at end of file
--
Gitee