+
+ 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\231\217\345\244\251\346\236\227/\347\254\224\350\256\260/20240516-\345\244\215\344\271\240.md" "b/\346\231\217\345\244\251\346\236\227/\347\254\224\350\256\260/20240516-\345\244\215\344\271\240.md"
new file mode 100644
index 0000000000000000000000000000000000000000..8b20c7fe20708df57745cbc80c8ce3c25f6bd1d9
--- /dev/null
+++ "b/\346\231\217\345\244\251\346\236\227/\347\254\224\350\256\260/20240516-\345\244\215\344\271\240.md"
@@ -0,0 +1,101 @@
+### 通过路由方式实现增删改查
+
+#### 思路概述:
+通过Vue Router实现增删改查功能,通常需要配置路由来映射不同的页面和操作。在这个过程中,需要定义路由路径、组件以及处理路由跳转等逻辑。
+
+#### 具体步骤:
+
+### 1. 配置路由
+在Vue项目中配置路由,定义不同的路由路径和对应的组件。
+
+```javascript
+// src/router/router.js
+import { createRouter, createWebHistory } from 'vue-router';
+import Home from './components/Home.vue';
+import Edit from './components/Edit.vue';
+
+const router = createRouter({
+ history: createWebHistory(),
+ routes: [
+ { path: '/home', component: Home },
+ { path: '/edit/:id?', name: 'Edit', component: Edit },
+ { path: '/', component: App },
+ ]
+});
+
+export default router;
+```
+
+### 2. 配置入口文件
+在入口文件中使用路由。
+
+```javascript
+// main.js
+import { createApp } from 'vue';
+import App from './App.vue';
+import router from './router/router';
+
+const app = createApp(App);
+app.use(router);
+app.mount('#app');
+```
+
+### 3. 创建视图组件
+在Vue项目中创建视图组件,如列表页面(Home.vue)和编辑页面(Edit.vue),用于展示数据和进行编辑操作。
+
+#### 列表页面(Home.vue)部分代码示例:
+```html
+