diff --git a/README.md b/README.md index 7cbc70e..2eb52f9 100644 --- a/README.md +++ b/README.md @@ -106,9 +106,10 @@ Quick Reference [RegEx 正则表达式](./docs/regex.md) [TypeScript](./docs/typescript.md) [Tauri](./docs/tauri.md) -[Vue 2](./docs/vue2.md) -[Vue 3](./docs/vue.md) +[Vue 2](./docs/vue2.md) +[Vue 3](./docs/vue.md) [ htmx](./docs/htmx.md) +[Pinia](./docs/pinia.md) ## CSS diff --git a/assets/pinia.svg b/assets/pinia.svg new file mode 100644 index 0000000..b8e1f63 --- /dev/null +++ b/assets/pinia.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/pinia.md b/docs/pinia.md index 5a7a35e..684a19d 100644 --- a/docs/pinia.md +++ b/docs/pinia.md @@ -16,25 +16,10 @@ yarn add pinia pnpm add pinia ``` -### 创建 Pinia 实例 - -在你的 Vue 应用中创建一个 Pinia 实例并将其传递给 Vue: - -```javascript -import { createApp } from 'vue' -import { createPinia } from 'pinia' -import App from './App.vue' - -const app = createApp(App) -const pinia = createPinia() - -app.use(pinia) -app.mount('#app') -``` - ### 定义 Store + -创建一个 store 文件(例如 `src/stores/counter.js`),并定义 store: +创建一个 store 文件(例如 `src/stores/counter.js`),并定义 `store` ```javascript import { defineStore } from 'pinia' @@ -54,9 +39,36 @@ export const useCounterStore = defineStore('counter', { }) ``` -### 使用 Store +### 创建 Pinia 实例 -在组件中使用 store: +```javascript +import { createApp } from 'vue' +import { createPinia } from 'pinia' +import App from './App.vue' + +const app = createApp(App) +const pinia = createPinia() + +app.use(pinia) +app.mount('#app') +``` + +在你的 [Vue](./vue.md) 应用中创建一个 Pinia 实例并将其传递给 [Vue](./vue.md) + +### 热重载 Store + +使用 Vite 时,你可以启用热重载功能: + +```javascript +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useCounterStore, import.meta.hot)) +} +``` + +### 使用 Store + + +在组件中使用 `store` ```javascript