| id | +姓名 | +性别 | +年龄 | +操作 | +
|---|---|---|---|---|
| {{ item.id }} | +{{ item.username }} | +{{ item.sex }} | +{{ item.age }} | ++ + + | +
| id | +姓名 | +性别 | +年龄 | +操作 | +
|---|---|---|---|---|
| {{ item.id }} | +{{ item.username }} | +{{ item.sex }} | +{{ item.age }} | ++ + + | +
姓名:
+性别:
+年龄:
++ + +
+姓名:
-- Gitee From d7f9245e6dd17dc140e77c7c0ad9d100c9949141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=BB=BA=E7=A5=A5?= <958464639@qq.com> Date: Thu, 16 May 2024 16:48:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6\200\201\350\267\257\347\224\261pinia.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git "a/\345\215\242\345\273\272\347\245\245/20240513-\345\212\250\346\200\201\350\267\257\347\224\261pinia.md" "b/\345\215\242\345\273\272\347\245\245/20240513-\345\212\250\346\200\201\350\267\257\347\224\261pinia.md" index 7915b6e..52ff7e2 100644 --- "a/\345\215\242\345\273\272\347\245\245/20240513-\345\212\250\346\200\201\350\267\257\347\224\261pinia.md" +++ "b/\345\215\242\345\273\272\347\245\245/20240513-\345\212\250\346\200\201\350\267\257\347\224\261pinia.md" @@ -1 +1,41 @@ ## 动态路由pinia +- Pinia 是一个用于管理 Vue 应用状态的轻量级状态管理库。 +1. 安装 Pinia: + - npm install pinia + - yarn add pinia + + +2. 创建 store:定义状态、 getter、 mutation 和 action。 + +```js +// 创建 store +const store = createStore({ + state: { + count: 0 + }, + mutations: { + increment(state) { + state.count++ + } + }, + actions: { + incrementAction(context) { + context.commit('increment') + } + } +}) +``` + + +3. 在组件中使用 store:通过注入 store 实例来访问和操作状态。 +```js +const app = createApp(App) +app.use(store) + +// 在组件中访问 store +const { count, incrementAction } = useStore() +``` +```html + +{{ count }}
+``` \ No newline at end of file -- Gitee