From 947bf65864bd44ab41cab683309d17a14ce7a30f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 15 May 2024 15:40:37 +0200 Subject: [PATCH] docs: refactor --- packages/docs/core-concepts/actions.md | 6 +- .../core-concepts/outside-component-usage.md | 2 +- packages/docs/introduction.md | 2 +- .../docs/zh/api/enums/pinia.MutationType.md | 12 +- .../pinia.DefineSetupStoreOptions.md | 14 +- .../interfaces/pinia.DefineStoreOptions.md | 32 +- .../pinia.DefineStoreOptionsBase.md | 10 +- .../pinia.DefineStoreOptionsInPlugin.md | 32 +- .../pinia.MapStoresCustomization.md | 2 +- .../docs/zh/api/interfaces/pinia.Pinia.md | 12 +- .../interfaces/pinia.PiniaCustomProperties.md | 18 +- .../pinia.PiniaCustomStateProperties.md | 8 +- .../zh/api/interfaces/pinia.PiniaPlugin.md | 6 +- .../interfaces/pinia.PiniaPluginContext.md | 20 +- .../api/interfaces/pinia.StoreDefinition.md | 24 +- .../api/interfaces/pinia.StoreProperties.md | 10 +- ...inia.SubscriptionCallbackMutationDirect.md | 10 +- ...bscriptionCallbackMutationPatchFunction.md | 10 +- ...SubscriptionCallbackMutationPatchObject.md | 16 +- .../pinia._StoreOnActionListenerContext.md | 28 +- .../api/interfaces/pinia._StoreWithState.md | 96 ++-- ...pinia._SubscriptionCallbackMutationBase.md | 6 +- .../pinia_testing.TestingOptions.md | 20 +- .../interfaces/pinia_testing.TestingPinia.md | 16 +- packages/docs/zh/api/modules/pinia.md | 518 +++++++++--------- packages/docs/zh/api/modules/pinia_nuxt.md | 10 +- packages/docs/zh/api/modules/pinia_testing.md | 6 +- packages/docs/zh/cookbook/composing-stores.md | 10 +- packages/docs/zh/cookbook/migration-v1-v2.md | 3 +- packages/docs/zh/cookbook/migration-vuex.md | 66 +-- packages/docs/zh/cookbook/options-api.md | 2 +- packages/docs/zh/cookbook/testing.md | 4 +- packages/docs/zh/core-concepts/actions.md | 10 +- packages/docs/zh/core-concepts/getters.md | 8 +- packages/docs/zh/core-concepts/plugins.md | 8 +- packages/docs/zh/core-concepts/state.md | 9 +- packages/docs/zh/getting-started.md | 2 +- packages/docs/zh/introduction.md | 6 +- packages/docs/zh/ssr/nuxt.md | 11 +- 39 files changed, 544 insertions(+), 541 deletions(-) diff --git a/packages/docs/core-concepts/actions.md b/packages/docs/core-concepts/actions.md index 3ca10b4f..c795219b 100644 --- a/packages/docs/core-concepts/actions.md +++ b/packages/docs/core-concepts/actions.md @@ -116,13 +116,13 @@ import { defineStore } from 'pinia' export const useCounterStore = defineStore('counter', { state: () => ({ - count: 0 + count: 0, }), actions: { increment() { this.count++ - } - } + }, + }, }) ``` diff --git a/packages/docs/core-concepts/outside-component-usage.md b/packages/docs/core-concepts/outside-component-usage.md index 2661586c..12f766fe 100644 --- a/packages/docs/core-concepts/outside-component-usage.md +++ b/packages/docs/core-concepts/outside-component-usage.md @@ -15,7 +15,7 @@ If you are not doing any SSR (Server Side Rendering), any call of `useStore()` a ```js import { useUserStore } from '@/stores/user' -import { createPinia } from 'pinia'; +import { createPinia } from 'pinia' import { createApp } from 'vue' import App from './App.vue' diff --git a/packages/docs/introduction.md b/packages/docs/introduction.md index bb77684c..c5e085c8 100644 --- a/packages/docs/introduction.md +++ b/packages/docs/introduction.md @@ -14,7 +14,7 @@ Pinia [started](https://github.com/vuejs/pinia/commit/06aeef54e2cad66696063c6282 ## Why should I use Pinia? - diff --git a/packages/docs/zh/api/enums/pinia.MutationType.md b/packages/docs/zh/api/enums/pinia.MutationType.md index 37dc64e9..990d4301 100644 --- a/packages/docs/zh/api/enums/pinia.MutationType.md +++ b/packages/docs/zh/api/enums/pinia.MutationType.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -16,7 +16,7 @@ SubscriptionCallback 的可能类型 ### direct %{#direct}% -• **direct** = ``"direct"`` +• **direct** = `"direct"` Direct mutation of the state: @@ -24,21 +24,21 @@ Direct mutation of the state: - `store.$state.name = 'new name'` - `store.list.push('new item')` -___ +--- ### patchFunction %{#patchfunction}% -• **patchFunction** = ``"patch function"`` +• **patchFunction** = `"patch function"` 通过 `$patch` 和一个函数更改 state: - `store.$patch(state => state.name = 'newName')` -___ +--- ### patchObject %{#patchobject}% -• **patchObject** = ``"patch object"`` +• **patchObject** = `"patch object"` 通过 `$patch` 和一个对象更改 state: diff --git a/packages/docs/zh/api/interfaces/pinia.DefineSetupStoreOptions.md b/packages/docs/zh/api/interfaces/pinia.DefineSetupStoreOptions.md index 905f7f1d..234d1ebd 100644 --- a/packages/docs/zh/api/interfaces/pinia.DefineSetupStoreOptions.md +++ b/packages/docs/zh/api/interfaces/pinia.DefineSetupStoreOptions.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -19,12 +19,12 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | -| `G` | `G` | -| `A` | `A` | +| 名称 | 类型 | +| :--- | :--------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | +| `G` | `G` | +| `A` | `A` | ## 层次结构 %{#hierarchy}% diff --git a/packages/docs/zh/api/interfaces/pinia.DefineStoreOptions.md b/packages/docs/zh/api/interfaces/pinia.DefineStoreOptions.md index 97e82677..08e67ef6 100644 --- a/packages/docs/zh/api/interfaces/pinia.DefineStoreOptions.md +++ b/packages/docs/zh/api/interfaces/pinia.DefineStoreOptions.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -19,12 +19,12 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名字 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | -| `G` | `G` | -| `A` | `A` | +| 名字 | 类型 | +| :--- | :--------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | +| `G` | `G` | +| `A` | `A` | ## 层次结构 %{#hierarchy}% @@ -40,7 +40,7 @@ sidebarDepth: 3 action 的可选对象 -___ +--- ### getters %{#getters}% @@ -48,7 +48,7 @@ ___ getter 的可选对象 -___ +--- ### id %{#id}% @@ -56,7 +56,7 @@ ___ 唯一的字符串密钥,用于识别整个应用中的 store。 -___ +--- ### state %{#state}% @@ -91,21 +91,21 @@ ___ ```ts const useStore = defineStore('main', { state: () => ({ - n: useLocalStorage('key', 0) + n: useLocalStorage('key', 0), }), hydrate(storeState, initialState) { // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826 storeState.n = useLocalStorage('key', 0) - } + }, }) ``` #### 参数 -| 名字 | 类型 | 描述 | -| :------ | :------ | :------ | -| `storeState` | `UnwrapRef`<`S`\> | the current state in the store | -| `initialState` | `UnwrapRef`<`S`\> | initialState | +| 名字 | 类型 | 描述 | +| :------------- | :---------------- | :----------------------------- | +| `storeState` | `UnwrapRef`<`S`\> | the current state in the store | +| `initialState` | `UnwrapRef`<`S`\> | initialState | #### 返回值 diff --git a/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsBase.md b/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsBase.md index 3ad0bd40..384110ce 100644 --- a/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsBase.md +++ b/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsBase.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -16,10 +16,10 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| Name | Type | -| :------ | :------ | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | -| `Store` | `Store` | +| Name | Type | +| :------ | :--------------------------------------------------- | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | +| `Store` | `Store` | ## 层次结构 %{#hierarchy}% diff --git a/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsInPlugin.md b/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsInPlugin.md index 6b0348b5..13b71528 100644 --- a/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsInPlugin.md +++ b/packages/docs/zh/api/interfaces/pinia.DefineStoreOptionsInPlugin.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -14,16 +14,16 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名字 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | -| `G` | `G` | -| `A` | `A` | +| 名字 | 类型 | +| :--- | :--------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | +| `G` | `G` | +| `A` | `A` | ## 层次结构 %{#hierarchy}% -- `Omit`<[`DefineStoreOptions`](pinia.DefineStoreOptions.md)<`Id`, `S`, `G`, `A`\>, ``"id"`` \| ``"actions"``\> +- `Omit`<[`DefineStoreOptions`](pinia.DefineStoreOptions.md)<`Id`, `S`, `G`, `A`\>, `"id"` \| `"actions"`\> ↳ **`DefineStoreOptionsInPlugin`** @@ -37,7 +37,7 @@ sidebarDepth: 3 否则使用传递给 `defineStore()` 的对象。 如果没有定义 action,则默认为一个空对象。 -___ +--- ### getters %{#getters}% @@ -49,7 +49,7 @@ getter 的可选对象 Omit.getters -___ +--- ### state @@ -88,21 +88,21 @@ Omit.state ```ts const useStore = defineStore('main', { state: () => ({ - n: useLocalStorage('key', 0) + n: useLocalStorage('key', 0), }), hydrate(storeState, initialState) { // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826 storeState.n = useLocalStorage('key', 0) - } + }, }) ``` #### 参数 -| 名字 | 类型 | 描述 | -| :------ | :------ | :------ | -| `storeState` | `UnwrapRef`<`S`\> | the current state in the store | -| `initialState` | `UnwrapRef`<`S`\> | initialState | +| 名字 | 类型 | 描述 | +| :------------- | :---------------- | :----------------------------- | +| `storeState` | `UnwrapRef`<`S`\> | the current state in the store | +| `initialState` | `UnwrapRef`<`S`\> | initialState | #### 返回值 diff --git a/packages/docs/zh/api/interfaces/pinia.MapStoresCustomization.md b/packages/docs/zh/api/interfaces/pinia.MapStoresCustomization.md index 79f63e72..b7527c3e 100644 --- a/packages/docs/zh/api/interfaces/pinia.MapStoresCustomization.md +++ b/packages/docs/zh/api/interfaces/pinia.MapStoresCustomization.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- diff --git a/packages/docs/zh/api/interfaces/pinia.Pinia.md b/packages/docs/zh/api/interfaces/pinia.Pinia.md index c98b216d..0914fccd 100644 --- a/packages/docs/zh/api/interfaces/pinia.Pinia.md +++ b/packages/docs/zh/api/interfaces/pinia.Pinia.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -30,15 +30,15 @@ Every application must own its own pinia to be able to create stores ##### 参数 -| Name | Type | -| :------ | :------ | +| Name | Type | +| :---- | :------------ | | `app` | `App`<`any`\> | ##### 返回值 `void` -___ +--- ### state %{#state}% @@ -56,8 +56,8 @@ ___ #### 参数 %{#paramters}% -| Name | Type | Description | -| :------ | :------ | :------ | +| Name | Type | Description | +| :------- | :------------------------------------ | :------------------ | | `plugin` | [`PiniaPlugin`](pinia.PiniaPlugin.md) | store plugin to add | #### 返回值 diff --git a/packages/docs/zh/api/interfaces/pinia.PiniaCustomProperties.md b/packages/docs/zh/api/interfaces/pinia.PiniaCustomProperties.md index efb0fd41..6ff75b82 100644 --- a/packages/docs/zh/api/interfaces/pinia.PiniaCustomProperties.md +++ b/packages/docs/zh/api/interfaces/pinia.PiniaCustomProperties.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -14,12 +14,12 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` = `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | -| `G` | [`_GettersTree`](../modules/pinia.md#_getterstree)<`S`\> | -| `A` | [`_ActionsTree`](../modules/pinia.md#_actionstree) | +| 名称 | 类型 | +| :--- | :-------------------------------------------------------------------------------------------------- | +| `Id` | extends `string` = `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | +| `G` | [`_GettersTree`](../modules/pinia.md#_getterstree)<`S`\> | +| `A` | [`_ActionsTree`](../modules/pinia.md#_actionstree) | ## Accessors %{#accessors}% @@ -35,8 +35,8 @@ sidebarDepth: 3 #### 参数 -| Name | Type | -| :------ | :------ | +| Name | Type | +| :------ | :------------------------------------------------------------------------- | | `value` | `RouteLocationNormalizedLoaded` \| `Ref`<`RouteLocationNormalizedLoaded`\> | #### 返回值 diff --git a/packages/docs/zh/api/interfaces/pinia.PiniaCustomStateProperties.md b/packages/docs/zh/api/interfaces/pinia.PiniaCustomStateProperties.md index c1aa1d3e..eb0056b4 100644 --- a/packages/docs/zh/api/interfaces/pinia.PiniaCustomStateProperties.md +++ b/packages/docs/zh/api/interfaces/pinia.PiniaCustomStateProperties.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -14,6 +14,6 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | +| 名称 | 类型 | +| :--- | :-------------------------------------------------------------------------------------------------- | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | diff --git a/packages/docs/zh/api/interfaces/pinia.PiniaPlugin.md b/packages/docs/zh/api/interfaces/pinia.PiniaPlugin.md index 819454b6..0a806559 100644 --- a/packages/docs/zh/api/interfaces/pinia.PiniaPlugin.md +++ b/packages/docs/zh/api/interfaces/pinia.PiniaPlugin.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -21,8 +21,8 @@ sidebarDepth: 3 #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------ | | `context` | [`PiniaPluginContext`](pinia.PiniaPluginContext.md)<`string`, [`StateTree`](../modules/pinia.md#statetree), [`_GettersTree`](../modules/pinia.md#_getterstree)<[`StateTree`](../modules/pinia.md#statetree)\>, [`_ActionsTree`](../modules/pinia.md#_actionstree)\> | Context | #### 返回值 diff --git a/packages/docs/zh/api/interfaces/pinia.PiniaPluginContext.md b/packages/docs/zh/api/interfaces/pinia.PiniaPluginContext.md index 69a86709..01a6bc12 100644 --- a/packages/docs/zh/api/interfaces/pinia.PiniaPluginContext.md +++ b/packages/docs/zh/api/interfaces/pinia.PiniaPluginContext.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -14,12 +14,12 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| Name | Type | -| :------ | :------ | -| `Id` | extends `string` = `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | -| `G` | [`_GettersTree`](../modules/pinia.md#_getterstree)<`S`\> | -| `A` | [`_ActionsTree`](../modules/pinia.md#_actionstree) | +| Name | Type | +| :--- | :-------------------------------------------------------------------------------------------------- | +| `Id` | extends `string` = `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | +| `G` | [`_GettersTree`](../modules/pinia.md#_getterstree)<`S`\> | +| `A` | [`_ActionsTree`](../modules/pinia.md#_actionstree) | ## 属性 @@ -29,7 +29,7 @@ sidebarDepth: 3 用 `Vue.createApp()`创建的当前应用。 -___ +--- ### options %{#options}% @@ -37,7 +37,7 @@ ___ 调用 `defineStore()` 时定义 store 的初始选项。 -___ +--- ### pinia %{#pinia}% @@ -45,7 +45,7 @@ ___ pinia 实例 -___ +--- ### store %{#store}% diff --git a/packages/docs/zh/api/interfaces/pinia.StoreDefinition.md b/packages/docs/zh/api/interfaces/pinia.StoreDefinition.md index 1a31816f..d1849963 100644 --- a/packages/docs/zh/api/interfaces/pinia.StoreDefinition.md +++ b/packages/docs/zh/api/interfaces/pinia.StoreDefinition.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -12,12 +12,12 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` = `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | -| `G` | [`_GettersTree`](../modules/pinia.md#_getterstree)<`S`\> | -| `A` | [`_ActionsTree`](../modules/pinia.md#_actionstree) | +| 名称 | 类型 | +| :--- | :-------------------------------------------------------------------------------------------------- | +| `Id` | extends `string` = `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) = [`StateTree`](../modules/pinia.md#statetree) | +| `G` | [`_GettersTree`](../modules/pinia.md#_getterstree)<`S`\> | +| `A` | [`_ActionsTree`](../modules/pinia.md#_actionstree) | ## Callable %{#callable}% @@ -29,10 +29,10 @@ sidebarDepth: 3 #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `pinia?` | ``null`` \| [`Pinia`](pinia.Pinia.md) | Pinia instance to retrieve the store | -| `hot?` | [`StoreGeneric`](../modules/pinia.md#storegeneric) | dev only hot module replacement | +| 名称 | 类型 | 描述 | +| :------- | :------------------------------------------------- | :----------------------------------- | +| `pinia?` | `null` \| [`Pinia`](pinia.Pinia.md) | Pinia instance to retrieve the store | +| `hot?` | [`StoreGeneric`](../modules/pinia.md#storegeneric) | dev only hot module replacement | #### 返回值 @@ -44,4 +44,4 @@ sidebarDepth: 3 • **$id**: `Id` - store 的 id。供映射辅助函数使用。 +store 的 id。供映射辅助函数使用。 diff --git a/packages/docs/zh/api/interfaces/pinia.StoreProperties.md b/packages/docs/zh/api/interfaces/pinia.StoreProperties.md index c1fd2078..46235052 100644 --- a/packages/docs/zh/api/interfaces/pinia.StoreProperties.md +++ b/packages/docs/zh/api/interfaces/pinia.StoreProperties.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -10,12 +10,12 @@ sidebarDepth: 3 [pinia](../modules/pinia.md).StoreProperties - store 的属性。 +store 的属性。 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :--- | :--------------- | | `Id` | extends `string` | ## 层次结构 %{#hierarchy}% @@ -32,7 +32,7 @@ sidebarDepth: 3 store 的唯一标识符 -___ +--- ### \_customProperties %{#customproperties}% diff --git a/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationDirect.md b/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationDirect.md index 4dd12224..0ca9b033 100644 --- a/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationDirect.md +++ b/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationDirect.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -28,7 +28,7 @@ sidebarDepth: 3 只支持开发环境。不同的 mutation 调用。 -___ +--- ### storeId %{#storeid}% @@ -38,9 +38,9 @@ ___ #### 继承于 -[_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[storeId](pinia._SubscriptionCallbackMutationBase.md#storeid) +[\_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[storeId](pinia._SubscriptionCallbackMutationBase.md#storeid) -___ +--- ### 类型 %{#type}% @@ -50,4 +50,4 @@ mutation 的类型 #### 重写 %{#overrides}% -[_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[type](pinia._SubscriptionCallbackMutationBase.md#type) +[\_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[type](pinia._SubscriptionCallbackMutationBase.md#type) diff --git a/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchFunction.md b/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchFunction.md index b4fd9001..421e2bdc 100644 --- a/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchFunction.md +++ b/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchFunction.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -27,7 +27,7 @@ sidebarDepth: 3 仅限开发环境。在回调中所有已完成的 mutation 的数组。 -___ +--- ### storeId %{#storeid}% @@ -37,9 +37,9 @@ ___ #### 继承于 -[_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[storeId](pinia._SubscriptionCallbackMutationBase.md#storeid) +[\_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[storeId](pinia._SubscriptionCallbackMutationBase.md#storeid) -___ +--- ### 类型 %{#type}% @@ -49,4 +49,4 @@ mutation 的类型 #### 重写 %{#overrides}% -[_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[type](pinia._SubscriptionCallbackMutationBase.md#type) +[\_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[type](pinia._SubscriptionCallbackMutationBase.md#type) diff --git a/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchObject.md b/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchObject.md index 4361605f..dad2f64e 100644 --- a/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchObject.md +++ b/packages/docs/zh/api/interfaces/pinia.SubscriptionCallbackMutationPatchObject.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -16,8 +16,8 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% | 名称 | -| :------ | -| `S` | +| :--- | +| `S` | ## 层次结构 %{#hierarchy}% @@ -33,7 +33,7 @@ sidebarDepth: 3 仅限 DEV, patch 调用的数组。 -___ +--- ### payload %{#payload}% @@ -41,7 +41,7 @@ ___ 传递给 `store.$patch()` 的对象 -___ +--- ### storeId %{#storeid}% @@ -51,9 +51,9 @@ ___ #### 继承于 -[_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[storeId](pinia._SubscriptionCallbackMutationBase.md#storeid) +[\_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[storeId](pinia._SubscriptionCallbackMutationBase.md#storeid) -___ +--- ### 类型 %{#type}% @@ -63,4 +63,4 @@ mutation 的类型 #### 重写 %{#overrides}% -[_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[type](pinia._SubscriptionCallbackMutationBase.md#type) +[\_SubscriptionCallbackMutationBase](pinia._SubscriptionCallbackMutationBase.md).[type](pinia._SubscriptionCallbackMutationBase.md#type) diff --git a/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md b/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md index bc4eeeb1..7e2ee298 100644 --- a/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md +++ b/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -8,7 +8,7 @@ sidebarDepth: 3 # 接口:\_StoreOnActionListenerContext %{#interface-storeonactionlistenercontext-store-actionname-a}% -[pinia](../modules/pinia.md)._StoreOnActionListenerContext +[pinia](../modules/pinia.md).\_StoreOnActionListenerContext [StoreOnActionListenerContext](../modules/pinia.md#storeonactionlistenercontext)的实际类型。 存在的目的是重构。仅供内部使用。 @@ -16,11 +16,11 @@ sidebarDepth: 3 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | -| `Store` | `Store` | +| 名称 | 类型 | +| :----------- | :--------------- | +| `Store` | `Store` | | `ActionName` | extends `string` | -| `A` | `A` | +| `A` | `A` | ## 属性 @@ -37,15 +37,15 @@ action 执行完的钩子。 ##### 参数 %{#parameters}% -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :--------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `callback` | `A` extends `Record`<`ActionName`, [`_Method`](../modules/pinia.md#_method)\> ? (`resolvedReturn`: [`_Awaited`](../modules/pinia.md#_awaited)<`ReturnType`<`A`[`ActionName`]\>\>) => `void` : () => `void` | ##### 返回值 `void` -___ +--- ### args %{#args}% @@ -53,7 +53,7 @@ ___ 传递给 action 的参数 -___ +--- ### name %{#name}% @@ -61,7 +61,7 @@ ___ action 的名称 -___ +--- ### onError %{#onerror}% @@ -76,15 +76,15 @@ action 的错误钩子。 ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :--------- | :----------------------------- | | `callback` | (`error`: `unknown`) => `void` | ##### 返回值 `void` -___ +--- ### store %{#store}% diff --git a/packages/docs/zh/api/interfaces/pinia._StoreWithState.md b/packages/docs/zh/api/interfaces/pinia._StoreWithState.md index 9537aee7..0d85c87a 100644 --- a/packages/docs/zh/api/interfaces/pinia._StoreWithState.md +++ b/packages/docs/zh/api/interfaces/pinia._StoreWithState.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -8,18 +8,18 @@ sidebarDepth: 3 # 接口:\_StoreWithState %{#interface-storewithstate-id-s-g-a}% -[pinia](../modules/pinia.md)._StoreWithState +[pinia](../modules/pinia.md).\_StoreWithState 具有 state 和部分功能的基础 store。不应直接使用。 ## 类型参数 %{#type-parameters}% -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | -| `G` | `G` | -| `A` | `A` | +| 名称 | 类型 | +| :--- | :--------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](../modules/pinia.md#statetree) | +| `G` | `G` | +| `A` | `A` | ## 层次结构 %{#hierarchy}% @@ -39,7 +39,7 @@ store 的唯一标识符 [StoreProperties](pinia.StoreProperties.md).[$id](pinia.StoreProperties.md#$id) -___ +--- ### $state %{#state}% @@ -47,7 +47,7 @@ ___ Store 的 State。给它赋值可替换整个 state。 -___ +--- ### \_customProperties %{#customproperties}% @@ -59,7 +59,7 @@ ___ #### 继承自 -[StoreProperties](pinia.StoreProperties.md).[_customProperties](pinia.StoreProperties.md#_customproperties) +[StoreProperties](pinia.StoreProperties.md).[\_customProperties](pinia.StoreProperties.md#_customproperties) ## 方法 %{#methods}% @@ -75,7 +75,7 @@ ___ `void` -___ +--- ### $onAction %{#onaction}% @@ -100,25 +100,25 @@ ___ ```js store.$onAction(({ after, onError }) => { - // 你可以在这里创建所有钩子之间的共享变量, - // 同时设置侦听器并清理它们。 - after((resolvedValue) => { - // 可以用来清理副作用 - // `resolvedValue` 是 action 返回的值, - // 如果是一个 Promise,它将是已经 resolved 的值 - }) - onError((error) => { - // 可以用于向上传递错误 - }) + // 你可以在这里创建所有钩子之间的共享变量, + // 同时设置侦听器并清理它们。 + after((resolvedValue) => { + // 可以用来清理副作用 + // `resolvedValue` 是 action 返回的值, + // 如果是一个 Promise,它将是已经 resolved 的值 + }) + onError((error) => { + // 可以用于向上传递错误 + }) }) ``` #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `callback` | [`StoreOnActionListener`](../modules/pinia.md#storeonactionlistener)<`Id`, `S`, `G`, `A`\> | callback called before every action | -| `detached?` | `boolean` | detach the subscription from the context this is called from | +| 名称 | 类型 | 描述 | +| :---------- | :----------------------------------------------------------------------------------------- | :----------------------------------------------------------- | +| `callback` | [`StoreOnActionListener`](../modules/pinia.md#storeonactionlistener)<`Id`, `S`, `G`, `A`\> | callback called before every action | +| `detached?` | `boolean` | detach the subscription from the context this is called from | #### 返回值 @@ -149,14 +149,14 @@ store.$onAction(({ after, onError }) => { store.$onAction(({ after, onError }) => { // 你可以在这里创建所有钩子之间的共享变量, // 同时设置侦听器并清理它们。 - after((resolvedValue) => { - // 可以用来清理副作用 - // `resolvedValue` 是 action 返回的值, - // 如果是一个 Promise,它将是已解决的值 - }) - onError((error) => { - // 可以用于向上传递错误 - }) + after((resolvedValue) => { + // 可以用来清理副作用 + // `resolvedValue` 是 action 返回的值, + // 如果是一个 Promise,它将是已解决的值 + }) + onError((error) => { + // 可以用于向上传递错误 + }) }) ``` @@ -166,7 +166,7 @@ store.$onAction(({ after, onError }) => { 移除侦听器的函数 -___ +--- ### $patch %{#patch}% @@ -176,8 +176,8 @@ ___ #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :------------- | :--------------------------------------------------------------------- | :-------------------------- | | `partialState` | [`_DeepPartial`](../modules/pinia.md#_deeppartial)<`UnwrapRef`<`S`\>\> | patch to apply to the state | #### 返回值 @@ -192,21 +192,21 @@ ___ #### 类型参数 %{#type-parameters_1}% -| 名称 | 类型 | -| :------ | :------ | -| `F` | extends (`state`: `UnwrapRef`<`S`\>) => `any` | +| 名称 | 类型 | +| :--- | :-------------------------------------------- | +| `F` | extends (`state`: `UnwrapRef`<`S`\>) => `any` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :------------- | :----------------------------------------------------------- | :--------------------------------------------- | | `stateMutator` | `ReturnType`<`F`\> extends `Promise`<`any`\> ? `never` : `F` | function that mutates `state`, cannot be async | #### 返回值 {returns} `void` -___ +--- ### $reset %{#reset}% @@ -219,7 +219,7 @@ TODO: make this options only `void` -___ +--- ### $subscribe %{#subscribe}% @@ -231,10 +231,10 @@ ___ #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `callback` | [`SubscriptionCallback`](../modules/pinia.md#subscriptioncallback)<`S`\> | callback passed to the watcher | -| `options?` | { `detached?`: `boolean` } & `WatchOptions`<`boolean`\> | `watch` options + `detached` to detach the subscription from the context (usually a component) this is called from. Note that the `flush` option does not affect calls to `store.$patch()`. | +| 名称 | 类型 | 描述 | +| :--------- | :----------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `callback` | [`SubscriptionCallback`](../modules/pinia.md#subscriptioncallback)<`S`\> | callback passed to the watcher | +| `options?` | { `detached?`: `boolean` } & `WatchOptions`<`boolean`\> | `watch` options + `detached` to detach the subscription from the context (usually a component) this is called from. Note that the `flush` option does not affect calls to `store.$patch()`. | #### 返回值 diff --git a/packages/docs/zh/api/interfaces/pinia._SubscriptionCallbackMutationBase.md b/packages/docs/zh/api/interfaces/pinia._SubscriptionCallbackMutationBase.md index d1be6957..b7fca862 100644 --- a/packages/docs/zh/api/interfaces/pinia._SubscriptionCallbackMutationBase.md +++ b/packages/docs/zh/api/interfaces/pinia._SubscriptionCallbackMutationBase.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -8,7 +8,7 @@ sidebarDepth: 3 # 接口:\_SubscriptionCallbackMutationBase %{#interface-subscriptioncallbackmutationbase}% -[pinia](../modules/pinia.md)._SubscriptionCallbackMutationBase +[pinia](../modules/pinia.md).\_SubscriptionCallbackMutationBase 传递给订阅回调的上下文的基本类型。内部类型。 @@ -30,7 +30,7 @@ sidebarDepth: 3 执行 mutation 的 store 的`id`。 -___ +--- ### 类型 %{#type}% diff --git a/packages/docs/zh/api/interfaces/pinia_testing.TestingOptions.md b/packages/docs/zh/api/interfaces/pinia_testing.TestingOptions.md index 61e7c928..ad2e09b5 100644 --- a/packages/docs/zh/api/interfaces/pinia_testing.TestingOptions.md +++ b/packages/docs/zh/api/interfaces/pinia_testing.TestingOptions.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -25,8 +25,8 @@ sidebarDepth: 3 ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :---- | :---------------------------- | | `fn?` | (...`args`: `any`[]) => `any` | ##### 返回值 @@ -37,15 +37,15 @@ sidebarDepth: 3 ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :-------- | :------ | | `...args` | `any`[] | ##### 返回值 `any` -___ +--- ### fakeApp %{#fakeapp}% @@ -56,7 +56,7 @@ ___ 因为插件**必须等待 pinia 安装好后才会执行**。 默认为 false。 -___ +--- ### initialState %{#initialstate}% @@ -65,7 +65,7 @@ ___ 允许你定义每个 store 的部分初始 state。 这个 state 会在 store 创建后被应用,这样可以让你只设置测试中需要的几个属性。 -___ +--- ### 插件 %{#plugins}% @@ -74,7 +74,7 @@ ___ 在测试插件之前必装的插件。 可以向你的应用添加测试时使用的任意插件。 -___ +--- ### stubActions %{#stubactions}% @@ -86,7 +86,7 @@ ___ 注意:当提供 `createSpy()` 时,它将**只**给 `fn` 参数 传递 `undefined`。 你仍然需要在 `createSpy()` 中处理这个问题。 -___ +--- ### stubPatch %{#stubpatch}% diff --git a/packages/docs/zh/api/interfaces/pinia_testing.TestingPinia.md b/packages/docs/zh/api/interfaces/pinia_testing.TestingPinia.md index 398174cc..40616622 100644 --- a/packages/docs/zh/api/interfaces/pinia_testing.TestingPinia.md +++ b/packages/docs/zh/api/interfaces/pinia_testing.TestingPinia.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -27,7 +27,7 @@ sidebarDepth: 3 Pinia 使用的应用 -___ +--- ### 安装 %{#install}% @@ -39,8 +39,8 @@ ___ ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :---- | :------------ | | `app` | `App`<`any`\> | ##### 返回值 @@ -51,7 +51,7 @@ ___ [Pinia](pinia.Pinia.md).[install](pinia.Pinia.md#install) -___ +--- ### state %{#state}% @@ -69,12 +69,12 @@ ___ ▸ **use**(`plugin`): [`Pinia`](pinia.Pinia.md) -增加了一个 store 插件来扩展每个 store +增加了一个 store 插件来扩展每个 store #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :------- | :------------------------------------ | :------------------ | | `plugin` | [`PiniaPlugin`](pinia.PiniaPlugin.md) | store plugin to add | #### 返回值 diff --git a/packages/docs/zh/api/modules/pinia.md b/packages/docs/zh/api/modules/pinia.md index ff6d930b..26a4b991 100644 --- a/packages/docs/zh/api/modules/pinia.md +++ b/packages/docs/zh/api/modules/pinia.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -45,7 +45,7 @@ sidebarDepth: 3 使用 PiniaPlugin 代替 -___ +--- ### StateTree %{#statetree}% @@ -53,7 +53,7 @@ ___ Store 的通用 state -___ +--- ### Store %{#store}% @@ -63,14 +63,14 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :--- | :--------------------------------------------- | +| 名称 | 类型 | +| :--- | :-------------------------------------------- | | `Id` | 扩展自 `string` = `string` | | `S` | 扩展自 [`StateTree`](pinia.md#statetree) = {} | -| `G` | {} | -| `A` | {} | +| `G` | {} | +| `A` | {} | -___ +--- ### StoreActions %{#storeactions}% @@ -85,7 +85,7 @@ ___ | :--- | | `SS` | -___ +--- ### StoreGeneric %{#storegeneric}% @@ -95,7 +95,7 @@ ___ 在访问字符串时不会失败, 这使得编写不在意传递的 store 类型的通用函数更加容易。 -___ +--- ### StoreGetters %{#storegetters}% @@ -110,7 +110,7 @@ ___ | :--- | | `SS` | -___ +--- ### StoreOnActionListener %{#storeonactionlistener}% @@ -118,12 +118,12 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :--- | :---------------------------------------- | +| 名称 | 类型 | +| :--- | :--------------------------------------- | | `Id` | 扩展自 `string` | | `S` | 扩展自 [`StateTree`](pinia.md#statetree) | -| `G` | `G` | -| `A` | `A` | +| `G` | `G` | +| `A` | `A` | #### 类型声明 %{#type-declaration}% @@ -133,15 +133,15 @@ ___ ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | [`StoreOnActionListenerContext`](pinia.md#storeonactionlistenercontext)<`Id`, `S`, `G`, {} extends `A` ? [`_ActionsTree`](pinia.md#_actionstree) : `A`\> | ##### 返回值 `void` -___ +--- ### StoreOnActionListenerContext %{#storeonactionlistenercontext}% @@ -152,14 +152,14 @@ TODO:应该只有Id,Store 和 Action 来生成适当的对象。 #### 类型参数 -| 名称 | 类型 | -| :--- | :---------------------------------------- | +| 名称 | 类型 | +| :--- | :--------------------------------------- | | `Id` | 扩展自 `string` | | `S` | 扩展自 [`StateTree`](pinia.md#statetree) | -| `G` | `G` | -| `A` | `A` | +| `G` | `G` | +| `A` | `A` | -___ +--- ### StoreState %{#storestate}% @@ -174,7 +174,7 @@ ___ | :--- | | `SS` | -___ +--- ### SubscriptionCallback %{#subscriptioncallback}% @@ -183,8 +183,8 @@ ___ #### 类型参数 | 名称 | -| :------ | -| `S` | +| :--- | +| `S` | #### 类型声明 %{#type-declaration_1}% @@ -194,16 +194,16 @@ ___ ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :--------- | :---------------------------------------------------------------------------- | | `mutation` | [`SubscriptionCallbackMutation`](pinia.md#subscriptioncallbackmutation)<`S`\> | -| `state` | `UnwrapRef`<`S`\> | +| `state` | `UnwrapRef`<`S`\> | ##### 返回值 `void` -___ +--- ### SubscriptionCallbackMutation %{#subscriptioncallbackmutation}% @@ -217,7 +217,7 @@ ___ | :--- | | `S` | -___ +--- ### \_ActionsTree %{#actionstree}% @@ -226,11 +226,11 @@ ___ 行动的对象的类型。仅供内部使用。 **仅**供内部使用 -___ +--- ### \_Awaited %{#awaited}% -Ƭ **\_Awaited**<`T`\>: `T` extends ``null`` \| `undefined` ? `T` : `T` extends `object` & { `then`: (`onfulfilled`: `F`) => `any` } ? `F` extends (`value`: infer V, ...`args`: `any`) => `any` ? [`_Awaited`](pinia.md#_awaited)<`V`\> : `never` : `T` +Ƭ **\_Awaited**<`T`\>: `T` extends `null` \| `undefined` ? `T` : `T` extends `object` & { `then`: (`onfulfilled`: `F`) => `any` } ? `F` extends (`value`: infer V, ...`args`: `any`) => `any` ? [`_Awaited`](pinia.md#_awaited)<`V`\> : `never` : `T` #### 类型参数 @@ -238,7 +238,7 @@ ___ | :--- | | `T` | -___ +--- ### \_DeepPartial %{#deeppartial}% @@ -251,10 +251,10 @@ ___ #### 类型参数 | 名称 | -| :------ | -| `T` | +| :--- | +| `T` | -___ +--- ### \_ExtractActionsFromSetupStore %{#extractactionsfromsetupstore}% @@ -265,14 +265,14 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | -___ +--- -### \_ExtractActionsFromSetupStore\_Keys %{#extractactionsfromsetupstore-keys}% +### \_ExtractActionsFromSetupStore_Keys %{#extractactionsfromsetupstore-keys}% -Ƭ **\_ExtractActionsFromSetupStore\_Keys**<`SS`\>: keyof { [K in keyof SS as SS[K] extends \_Method ? K : never]: any } +Ƭ **\_ExtractActionsFromSetupStore_Keys**<`SS`\>: keyof { [K in keyof SS as SS[K] extends \_Method ? K : never]: any } 能够通过 IDE 进行重构的类型。 **仅**供内部使用 @@ -280,10 +280,10 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | -___ +--- ### \_ExtractGettersFromSetupStore %{#extractgettersfromsetupstore}% @@ -294,14 +294,14 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | -___ +--- -### \_ExtractGettersFromSetupStore\_Keys %{#extractgettersfromsetupstore-keys}% +### \_ExtractGettersFromSetupStore_Keys %{#extractgettersfromsetupstore-keys}% -Ƭ **\_ExtractGettersFromSetupStore\_Keys**<`SS`\>: keyof { [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any } +Ƭ **\_ExtractGettersFromSetupStore_Keys**<`SS`\>: keyof { [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any } 能够通过 IDE 进行重构的类型。 **仅**供内部使用 @@ -309,10 +309,10 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | -___ +--- ### \_ExtractStateFromSetupStore %{#extractstatefromsetupstore}% @@ -323,14 +323,14 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | -___ +--- -### \_ExtractStateFromSetupStore\_Keys %{#extractstatefromsetupstore-keys}% +### \_ExtractStateFromSetupStore_Keys %{#extractstatefromsetupstore-keys}% -Ƭ **\_ExtractStateFromSetupStore\_Keys**<`SS`\>: keyof { [K in keyof SS as SS[K] extends \_Method \| ComputedRef ? never : K]: any } +Ƭ **\_ExtractStateFromSetupStore_Keys**<`SS`\>: keyof { [K in keyof SS as SS[K] extends \_Method \| ComputedRef ? never : K]: any } 能够通过 IDE 进行重构的类型。 **仅**供内部使用 @@ -338,10 +338,10 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | -___ +--- ### \_GettersTree %{#getterstree}% @@ -352,11 +352,11 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `S` | extends [`StateTree`](pinia.md#statetree) | +| 名称 | 类型 | +| :--- | :---------------------------------------- | +| `S` | extends [`StateTree`](pinia.md#statetree) | -___ +--- ### \_MapActionsObjectReturn %{#mapactionsobjectreturn}% @@ -366,12 +366,12 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `A` | `A` | -| `T` | extends `Record`<`string`, keyof `A`\> | +| 名称 | 类型 | +| :--- | :------------------------------------- | +| `A` | `A` | +| `T` | extends `Record`<`string`, keyof `A`\> | -___ +--- ### \_MapActionsReturn %{#mapactionsreturn}% @@ -382,10 +382,10 @@ ___ #### 类型参数 | 名称 | -| :------ | -| `A` | +| :--- | +| `A` | -___ +--- ### \_MapStateObjectReturn %{#mapstateobjectreturn}% @@ -395,15 +395,15 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | -| `T` | extends `Record`<`string`, keyof `S` \| keyof `G` \| (`store`: [`Store`](pinia.md#store)<`Id`, `S`, `G`, `A`\>) => `any`\> = {} | +| 名称 | 类型 | +| :--- | :------------------------------------------------------------------------------------------------------------------------------ | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | +| `T` | extends `Record`<`string`, keyof `S` \| keyof `G` \| (`store`: [`Store`](pinia.md#store)<`Id`, `S`, `G`, `A`\>) => `any`\> = {} | -___ +--- ### \_MapStateReturn %{#mapstatereturn}% @@ -413,13 +413,13 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| 名称 | 类型 | +| :----- | :------------------------------------------------------ | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | | `Keys` | extends keyof `S` \| keyof `G` = keyof `S` \| keyof `G` | -___ +--- ### \_MapWritableStateObjectReturn %{#mapwritablestateobjectreturn}% @@ -429,12 +429,12 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `T` | extends `Record`<`string`, keyof `S`\> | +| 名称 | 类型 | +| :--- | :---------------------------------------- | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `T` | extends `Record`<`string`, keyof `S`\> | -___ +--- ### \_MapWritableStateReturn %{#mapwritablestatereturn}% @@ -444,11 +444,11 @@ ___ #### 类型参数 -| 名称 | Type | -| :------ | :------ | -| `S` | extends [`StateTree`](pinia.md#statetree) | +| 名称 | Type | +| :--- | :---------------------------------------- | +| `S` | extends [`StateTree`](pinia.md#statetree) | -___ +--- ### \_Method %{#method}% @@ -464,15 +464,15 @@ ___ ##### 参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :-------- | :------ | | `...args` | `any`[] | ##### 返回值 `any` -___ +--- ### \_Spread %{#spread}% @@ -482,11 +482,11 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `A` | extends readonly `any`[] | +| 名称 | 类型 | +| :--- | :----------------------- | +| `A` | extends readonly `any`[] | -___ +--- ### \_StoreObject %{#storeobject}% @@ -497,10 +497,10 @@ ___ #### 类型参数 | 名称 | -| :------ | -| `S` | +| :--- | +| `S` | -___ +--- ### \_StoreWithActions %{#storewithactions}% @@ -512,10 +512,10 @@ ___ #### 类型参数 | 名称 | -| :------ | -| `A` | +| :--- | +| `A` | -___ +--- ### \_StoreWithGetters %{#storewithgetters}% @@ -527,10 +527,10 @@ Store augmented with getters. For internal usage only. #### 类型参数 | 名称 | -| :------ | -| `G` | +| :--- | +| `G` | -___ +--- ### \_UnwrapAll %{#unwrapall}% @@ -542,7 +542,7 @@ ___ #### 类型参数 | 名称 | -| :------ | +| :--- | | `SS` | ## 变量 %{#variables}% @@ -573,7 +573,7 @@ new Vue({ **`param`** - 从 'vue' 导入的 `Vue`。 +从 'vue' 导入的 `Vue`。 ## 函数 %{#functions}% @@ -594,10 +594,10 @@ if (import.meta.hot) { #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------- | | `initialUseStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`string`, [`StateTree`](pinia.md#statetree), [`_GettersTree`](pinia.md#_getterstree)<[`StateTree`](pinia.md#statetree)\>, [`_ActionsTree`](pinia.md#_actionstree)\> | return of the defineStore to hot update | -| `hot` | `any` | `import.meta.hot` | +| `hot` | `any` | `import.meta.hot` | #### 返回值 @@ -615,7 +615,7 @@ if (import.meta.hot) { `any` -___ +--- ### createPinia %{#createpinia}% @@ -627,7 +627,7 @@ ___ [`Pinia`](../interfaces/pinia.Pinia.md) -___ +--- ### defineStore %{#definestore}% @@ -637,19 +637,19 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :--- | :--------------------------------------------- | +| 名称 | 类型 | +| :--- | :-------------------------------------------- | | `Id` | 扩展自 `string` | | `S` | 扩展自 [`StateTree`](pinia.md#statetree) = {} | | `G` | 扩展自 `_GettersTree`<`S`\> = {} | -| `A` | {} | +| `A` | {} | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `id` | `Id` | id of the store (must be unique) | -| `options` | `Omit`<[`DefineStoreOptions`](../interfaces/pinia.DefineStoreOptions.md)<`Id`, `S`, `G`, `A`\>, ``"id"``\> | options to define the store | +| 名称 | 类型 | 描述 | +| :-------- | :------------------------------------------------------------------------------------------------------- | :------------------------------- | +| `id` | `Id` | id of the store (must be unique) | +| `options` | `Omit`<[`DefineStoreOptions`](../interfaces/pinia.DefineStoreOptions.md)<`Id`, `S`, `G`, `A`\>, `"id"`\> | options to define the store | #### 返回值 @@ -661,17 +661,17 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :--- | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) = {} | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> = {} | -| `A` | {} | +| 名称 | 类型 | +| :--- | :--------------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) = {} | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> = {} | +| `A` | {} | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :-------- | :-------------------------------------------------------------------------------------- | :-------------------------- | | `options` | [`DefineStoreOptions`](../interfaces/pinia.DefineStoreOptions.md)<`Id`, `S`, `G`, `A`\> | options to define the store | #### 返回值 @@ -684,24 +684,24 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :--- | :--------------- | +| 名称 | 类型 | +| :--- | :-------------- | | `Id` | 扩展自 `string` | -| `SS` | `SS` | +| `SS` | `SS` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `id` | `Id` | id of the store (must be unique) | -| `storeSetup` | () => `SS` | function that defines the store | -| `options?` | [`DefineSetupStoreOptions`](../interfaces/pinia.DefineSetupStoreOptions.md)<`Id`, [`_ExtractStateFromSetupStore`](pinia.md#_extractstatefromsetupstore)<`SS`\>, [`_ExtractGettersFromSetupStore`](pinia.md#_extractgettersfromsetupstore)<`SS`\>, [`_ExtractActionsFromSetupStore`](pinia.md#_extractactionsfromsetupstore)<`SS`\>\> | extra options | +| 名称 | 类型 | 描述 | +| :----------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------- | +| `id` | `Id` | id of the store (must be unique) | +| `storeSetup` | () => `SS` | function that defines the store | +| `options?` | [`DefineSetupStoreOptions`](../interfaces/pinia.DefineSetupStoreOptions.md)<`Id`, [`_ExtractStateFromSetupStore`](pinia.md#_extractstatefromsetupstore)<`SS`\>, [`_ExtractGettersFromSetupStore`](pinia.md#_extractgettersfromsetupstore)<`SS`\>, [`_ExtractActionsFromSetupStore`](pinia.md#_extractactionsfromsetupstore)<`SS`\>\> | extra options | #### 返回值 [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, [`_ExtractStateFromSetupStore`](pinia.md#_extractstatefromsetupstore)<`SS`\>, [`_ExtractGettersFromSetupStore`](pinia.md#_extractgettersfromsetupstore)<`SS`\>, [`_ExtractActionsFromSetupStore`](pinia.md#_extractactionsfromsetupstore)<`SS`\>\> -___ +--- ### getActivePinia %{#getactivepinia}% @@ -713,7 +713,7 @@ ___ `undefined` \| [`Pinia`](../interfaces/pinia.Pinia.md) -___ +--- ### mapActions %{#mapactions}% @@ -731,32 +731,32 @@ export default { methods: { // 其他方法属性 // useCounterStore 有两个 action,分别是 `increment` 与 `setCount`。 - ...mapActions(useCounterStore, { moar: 'increment', setIt: 'setCount' }) + ...mapActions(useCounterStore, { moar: 'increment', setIt: 'setCount' }), }, created() { this.moar() this.setIt(2) - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :---------- | :---------------------------------------- | +| 名称 | 类型 | +| :---------- | :--------------------------------------- | | `Id` | 扩展自 `string` | | `S` | 扩展自 [`StateTree`](pinia.md#statetree) | | `G` | 扩展自 `_GettersTree`<`S`\> | -| `A` | `A` | +| `A` | `A` | | `KeyMapper` | 扩展自 `Record`<`string`, keyof `A`\> | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keyMapper` | `KeyMapper` | object to define new names for the actions | +| 名称 | 类型 | 描述 | +| :---------- | :-------------------------------------------------------------------------------- | :----------------------------------------- | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keyMapper` | `KeyMapper` | object to define new names for the actions | #### 返回值 @@ -774,37 +774,37 @@ export default { export default { methods: { // 其他方法属性 - ...mapActions(useCounterStore, ['increment', 'setCount']) + ...mapActions(useCounterStore, ['increment', 'setCount']), }, created() { this.increment() this.setCount(2) // 像往常一样传递参数 - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :--- | :---------------------------------------- | -| `Id` | 扩展自 `string` | -| `S` | 扩展自 [`StateTree`](pinia.md#statetree) | +| 名称 | 类型 | +| :--- | :--------------------------------------------------- | +| `Id` | 扩展自 `string` | +| `S` | 扩展自 [`StateTree`](pinia.md#statetree) | | `G` | 扩展自 [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | +| `A` | `A` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keys` | keyof `A`[] | array of action names to map | +| 名称 | 类型 | 描述 | +| :--------- | :-------------------------------------------------------------------------------- | :--------------------------- | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keys` | keyof `A`[] | array of action names to map | #### 返回值 [`_MapActionsReturn`](pinia.md#_mapactionsreturn)<`A`\> -___ +--- ### mapGetters %{#mapgetters}% @@ -827,38 +827,38 @@ export default { // useCounterStore 有一个名为 `count` 的 state 属性以及一个名为 `double` 的 getter ...mapState(useCounterStore, { n: 'count', - triple: store => store.n * 3, + triple: (store) => store.n * 3, // 注意如果你想要使用 `this`,那你不能使用箭头函数 custom(store) { return this.someComponentValue + store.n }, - doubleN: 'double' - }) + doubleN: 'double', + }), }, created() { this.n // 2 this.doubleN // 4 - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | +| 名称 | 类型 | +| :---------- | :------------------------------------------------------------------------------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | | `KeyMapper` | extends `Record`<`string`, keyof `S` \| keyof `G` \| (`store`: [`Store`](pinia.md#store)<`Id`, `S`, `G`, `A`\>) => `any`\> | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keyMapper` | `KeyMapper` | object of state properties or getters | +| 名称 | 类型 | 描述 | +| :---------- | :-------------------------------------------------------------------------------- | :------------------------------------ | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keyMapper` | `KeyMapper` | object of state properties or getters | #### 返回值 @@ -876,38 +876,38 @@ export default { export default { computed: { // 其他计算属性 - ...mapState(useCounterStore, ['count', 'double']) + ...mapState(useCounterStore, ['count', 'double']), }, created() { this.count // 2 this.double // 4 - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | -| `Keys` | extends `string` \| `number` \| `symbol` | +| 名称 | 类型 | +| :----- | :---------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | +| `Keys` | extends `string` \| `number` \| `symbol` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keys` | readonly `Keys`[] | array of state properties or getters | +| 名称 | 类型 | 描述 | +| :--------- | :-------------------------------------------------------------------------------- | :----------------------------------- | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keys` | readonly `Keys`[] | array of state properties or getters | #### 返回值 [`_MapStateReturn`](pinia.md#_mapstatereturn)<`S`, `G`, `Keys`\> -___ +--- ### mapState %{#mapstate}% @@ -929,38 +929,38 @@ export default { // useCounterStore 拥有一个名为 `count` 的 state 属性和一个名为 `double` 的 getter ...mapState(useCounterStore, { n: 'count', - triple: store => store.n * 3, + triple: (store) => store.n * 3, // 如果想使用 `this`,就不能使用箭头函数 custom(store) { return this.someComponentValue + store.n }, - doubleN: 'double' - }) + doubleN: 'double', + }), }, created() { this.n // 2 this.doubleN // 4 - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | +| 名称 | 类型 | +| :---------- | :------------------------------------------------------------------------------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | | `KeyMapper` | extends `Record`<`string`, keyof `S` \| keyof `G` \| (`store`: [`Store`](pinia.md#store)<`Id`, `S`, `G`, `A`\>) => `any`\> | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keyMapper` | `KeyMapper` | object of state properties or getters | +| 名称 | 类型 | 描述 | +| :---------- | :-------------------------------------------------------------------------------- | :------------------------------------ | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keyMapper` | `KeyMapper` | object of state properties or getters | #### 返回值 @@ -978,38 +978,38 @@ export default { export default { computed: { // 其他计算属性 - ...mapState(useCounterStore, ['count', 'double']) + ...mapState(useCounterStore, ['count', 'double']), }, created() { this.count // 2 this.double // 4 - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | -| `Keys` | extends `string` \| `number` \| `symbol` | +| 名称 | 类型 | +| :----- | :---------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | +| `Keys` | extends `string` \| `number` \| `symbol` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keys` | readonly `Keys`[] | array of state properties or getters | +| 名称 | 类型 | 描述 | +| :--------- | :-------------------------------------------------------------------------------- | :----------------------------------- | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keys` | readonly `Keys`[] | array of state properties or getters | #### 返回值 [`_MapStateReturn`](pinia.md#_mapstatereturn)<`S`, `G`, `Keys`\> -___ +--- ### mapStores %{#mapstores}% @@ -1025,25 +1025,25 @@ ___ export default { computed: { // 其他计算属性 - ...mapStores(useUserStore, useCartStore) + ...mapStores(useUserStore, useCartStore), }, created() { this.userStore // id 为 "user" 的 store this.cartStore // id 为 "cart" 的 store - } + }, } ``` #### 类型参数 -| 名称 | 类型 | -| :------- | :-------------- | +| 名称 | 类型 | +| :------- | :----------- | | `Stores` | 扩展 `any`[] | #### 参数 -| 名称 | 类型 | 描述 | +| 名称 | 类型 | 描述 | | :---------- | :------------ | :--------------------------------- | | `...stores` | [...Stores[]] | list of stores to map to an object | @@ -1051,7 +1051,7 @@ export default { [`_Spread`](pinia.md#_spread)<`Stores`\> -___ +--- ### mapWritableState %{#mapwritablestate}% @@ -1063,20 +1063,20 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | -| `KeyMapper` | extends `Record`<`string`, keyof `S`\> | +| 名称 | 类型 | +| :---------- | :---------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | +| `KeyMapper` | extends `Record`<`string`, keyof `S`\> | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keyMapper` | `KeyMapper` | object of state properties | +| 名称 | 类型 | 描述 | +| :---------- | :-------------------------------------------------------------------------------- | :------------------------- | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keyMapper` | `KeyMapper` | object of state properties | #### 返回值 @@ -1090,25 +1090,25 @@ ___ #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | -| `Id` | extends `string` | -| `S` | extends [`StateTree`](pinia.md#statetree) | -| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | -| `A` | `A` | +| 名称 | 类型 | +| :--- | :---------------------------------------------------- | +| `Id` | extends `string` | +| `S` | extends [`StateTree`](pinia.md#statetree) | +| `G` | extends [`_GettersTree`](pinia.md#_getterstree)<`S`\> | +| `A` | `A` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | -| `keys` | keyof `S`[] | array of state properties | +| 名称 | 类型 | 描述 | +| :--------- | :-------------------------------------------------------------------------------- | :------------------------ | +| `useStore` | [`StoreDefinition`](../interfaces/pinia.StoreDefinition.md)<`Id`, `S`, `G`, `A`\> | store to map from | +| `keys` | keyof `S`[] | array of state properties | #### 返回值 [`_MapWritableStateReturn`](pinia.md#_mapwritablestatereturn)<`S`\> -___ +--- ### setActivePinia %{#setactivepinia}% @@ -1119,15 +1119,15 @@ ___ #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :------ | :----------------------------------------------------- | :------------- | | `pinia` | `undefined` \| [`Pinia`](../interfaces/pinia.Pinia.md) | Pinia instance | #### 返回值 `undefined` \| [`Pinia`](../interfaces/pinia.Pinia.md) -___ +--- ### setMapStoreSuffix %{#setmapstoresuffix}% @@ -1139,15 +1139,15 @@ ___ #### 参数 %{#parameters}% -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :------- | :------- | :--------- | | `suffix` | `string` | new suffix | #### 返回值 `void` -___ +--- ### skipHydrate %{#skiphydrate}% @@ -1159,14 +1159,14 @@ ___ #### 类型参数 | 名称 | 类型 | -| :------ | :------ | -| `T` | `any` | +| :--- | :---- | +| `T` | `any` | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `obj` | `T` | target object | +| 名称 | 类型 | 描述 | +| :---- | :--- | :------------ | +| `obj` | `T` | target object | #### 返回值 @@ -1174,7 +1174,7 @@ ___ obj -___ +--- ### storeToRefs %{#storetorefs}% @@ -1187,16 +1187,16 @@ getter 和 plugin 添加的 state 属性。 #### 类型参数 -| 名称 | 类型 | -| :------ | :------ | +| 名称 | 类型 | +| :--- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `SS` | extends [`_StoreWithState`](../interfaces/pinia._StoreWithState.md)<`string`, [`StateTree`](pinia.md#statetree), [`_GettersTree`](pinia.md#_getterstree)<[`StateTree`](pinia.md#statetree)\>, [`_ActionsTree`](pinia.md#_actionstree), `SS`\> & [`StateTree`](pinia.md#statetree) & [`_StoreWithGetters`](pinia.md#_storewithgetters)<[`_GettersTree`](pinia.md#_getterstree)<[`StateTree`](pinia.md#statetree)\>\> & [`PiniaCustomProperties`](../interfaces/pinia.PiniaCustomProperties.md)<`string`, [`StateTree`](pinia.md#statetree), [`_GettersTree`](pinia.md#_getterstree)<[`StateTree`](pinia.md#statetree)\>, [`_ActionsTree`](pinia.md#_actionstree), `SS`\> & [`PiniaCustomStateProperties`](../interfaces/pinia.PiniaCustomStateProperties.md)<[`StateTree`](pinia.md#statetree), `SS`\> | #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :--- | :------ | +| 名称 | 类型 | 描述 | +| :------ | :--- | :----------------------------- | | `store` | `SS` | store to extract the refs from | #### 返回值 -`ToRefs`<[`StoreState`](pinia.md#storestate)<`SS`\> & [`StoreGetters`](pinia.md#storegetters)<`SS`\> & [`PiniaCustomStateProperties`](../interfaces/pinia.PiniaCustomStateProperties.md)<[`StoreState`](pinia.md#storestate)<`SS`\>\>\> \ No newline at end of file +`ToRefs`<[`StoreState`](pinia.md#storestate)<`SS`\> & [`StoreGetters`](pinia.md#storegetters)<`SS`\> & [`PiniaCustomStateProperties`](../interfaces/pinia.PiniaCustomStateProperties.md)<[`StoreState`](pinia.md#storestate)<`SS`\>\>\> diff --git a/packages/docs/zh/api/modules/pinia_nuxt.md b/packages/docs/zh/api/modules/pinia_nuxt.md index 4bc53cf7..be4e75f3 100644 --- a/packages/docs/zh/api/modules/pinia_nuxt.md +++ b/packages/docs/zh/api/modules/pinia_nuxt.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -20,11 +20,11 @@ sidebarDepth: 3 #### 参数 -| Name | Type | -| :------ | :------ | -| `this` | `void` | +| Name | Type | +| :-------------- | :----------------------------------------------------------- | +| `this` | `void` | | `inlineOptions` | [`ModuleOptions`](../interfaces/pinia_nuxt.ModuleOptions.md) | -| `nuxt` | `Nuxt` | +| `nuxt` | `Nuxt` | #### 返回值 diff --git a/packages/docs/zh/api/modules/pinia_testing.md b/packages/docs/zh/api/modules/pinia_testing.md index 64cb5c0c..9bbdc8ac 100644 --- a/packages/docs/zh/api/modules/pinia_testing.md +++ b/packages/docs/zh/api/modules/pinia_testing.md @@ -1,5 +1,5 @@ --- -sidebar: "auto" +sidebar: 'auto' editLinks: false sidebarDepth: 3 --- @@ -28,8 +28,8 @@ sidebarDepth: 3 #### 参数 -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | +| 名称 | 类型 | 描述 | +| :-------- | :---------------------------------------------------------------- | :------------------------ | | `options` | [`TestingOptions`](../interfaces/pinia_testing.TestingOptions.md) | 配置 pinia 测试实例的选项 | #### 返回值 diff --git a/packages/docs/zh/cookbook/composing-stores.md b/packages/docs/zh/cookbook/composing-stores.md index 9b8a8def..41fb35ce 100644 --- a/packages/docs/zh/cookbook/composing-stores.md +++ b/packages/docs/zh/cookbook/composing-stores.md @@ -2,7 +2,7 @@ 组合式 store 是可以相互使用,Pinia 当然也支持它。但有一个规则需要遵循: -如果**两个或更多的 store 相互使用**,它们不可以通过 *getters* 或 *actions* 创建一个无限循环。它们也不可以**同时**在它们的 setup 函数中直接互相读取对方的 state: +如果**两个或更多的 store 相互使用**,它们不可以通过 _getters_ 或 _actions_ 创建一个无限循环。它们也不可以**同时**在它们的 setup 函数中直接互相读取对方的 state: ```js const useX = defineStore('x', () => { @@ -42,9 +42,9 @@ const useY = defineStore('y', () => { ## 嵌套 store %{#nested-stores}% -注意,如果一个 store 使用另一个 store,你可以直接导入并在 *actions* 和 *getters* 中调用 `useStore()` 函数。然后你就可以像在 Vue 组件中那样使用 store。参考[共享 Getter](#shared-getters) 和[共享 Action](#shared-actions)。 +注意,如果一个 store 使用另一个 store,你可以直接导入并在 _actions_ 和 _getters_ 中调用 `useStore()` 函数。然后你就可以像在 Vue 组件中那样使用 store。参考[共享 Getter](#shared-getters) 和[共享 Action](#shared-actions)。 -对于 *setup store* ,你直接使用 store 函数**顶部**的一个 store: +对于 _setup store_ ,你直接使用 store 函数**顶部**的一个 store: ```ts import { useUserStore } from './user' @@ -67,7 +67,7 @@ export const useCartStore = defineStore('cart', () => { ## 共享 Getter %{#shared-getters}% -你可以直接在一个 *getter* 中调用 `useOtherStore()`: +你可以直接在一个 _getter_ 中调用 `useOtherStore()`: ```js import { defineStore } from 'pinia' @@ -86,7 +86,7 @@ export const useCartStore = defineStore('cart', { ## 共享 Actions %{#shared-actions}% -*actions* 也一样: +_actions_ 也一样: ```js import { defineStore } from 'pinia' diff --git a/packages/docs/zh/cookbook/migration-v1-v2.md b/packages/docs/zh/cookbook/migration-v1-v2.md index 91d6848f..3f3cb089 100644 --- a/packages/docs/zh/cookbook/migration-v1-v2.md +++ b/packages/docs/zh/cookbook/migration-v1-v2.md @@ -17,7 +17,7 @@ yarn add 'pinia@^0.x.x' - `createStore()` 变成 `defineStore()` - 在订阅中,`storeName` 变成 `storeId` - `PiniaPlugin` 更名为 `PiniaVuePlugin`(Vue 2 的 Pinia 插件) -- `$subscribe()` 不再接受 *boolean* 作为第二个参数,而是传递一个带有 `detached: true` 的对象。 +- `$subscribe()` 不再接受 _boolean_ 作为第二个参数,而是传递一个带有 `detached: true` 的对象。 - Pinia 插件不再直接接收 store 的 `id`。使用 `store.$id` 代替。 ## 非兼容性更新 %{#breaking-changes}% @@ -100,6 +100,7 @@ Can't import the named export 'computed' from non EcmaScript module (only defaul 这是构建文件为支持 Node.js 中的原生 ESM 模块进行的现代化适配。为更好地支持 Node,文件现在使用的扩展名是 `.mjs` 和 `.cjs`。要解决这个问题,你有两种可用的方法: - 如果你使用 Vue CLI 4.x,升级你的依赖。具体修复步骤如下。 + - 如果你不可能升级,请将下面的代码添加到你的 `vue.config.js` 中: ```js diff --git a/packages/docs/zh/cookbook/migration-vuex.md b/packages/docs/zh/cookbook/migration-vuex.md index ce2ba065..bae87804 100644 --- a/packages/docs/zh/cookbook/migration-vuex.md +++ b/packages/docs/zh/cookbook/migration-vuex.md @@ -10,7 +10,7 @@ Vuex 有一个概念,带有多个模块的单一 store。这些模块可以被命名,甚至可以互相嵌套。 -将这个概念过渡到 Pinia 最简单的方法是,你以前使用的每个模块现在都是一个 *store*。每个 store 都需要一个 `id`,类似于 Vuex 中的命名空间。这意味着每个 store 都有命名空间的设计。嵌套模块也可以成为自己的 store。互相依赖的 store 可以直接导入其他 store。 +将这个概念过渡到 Pinia 最简单的方法是,你以前使用的每个模块现在都是一个 _store_。每个 store 都需要一个 `id`,类似于 Vuex 中的命名空间。这意味着每个 store 都有命名空间的设计。嵌套模块也可以成为自己的 store。互相依赖的 store 可以直接导入其他 store。 你的 Vuex 模块如何重构为 Pinia store,完全取决于你,不过这里有一个示例: @@ -63,7 +63,7 @@ const storeModule: Module = { state: { firstName: '', lastName: '', - userId: null + userId: null, }, getters: { firstName: (state) => state.firstName, @@ -77,29 +77,29 @@ const storeModule: Module = { // 读取另一个名为 `auth` 模块的 state ...rootState.auth.preferences, // 读取嵌套于 `auth` 模块的 `email` 模块的 getter - ...rootGetters['auth/email'].details + ...rootGetters['auth/email'].details, } - } + }, }, actions: { - async loadUser ({ state, commit }, id: number) { + async loadUser({ state, commit }, id: number) { if (state.userId !== null) throw new Error('Already logged in') const res = await api.user.load(id) commit('updateUser', res) - } + }, }, mutations: { - updateUser (state, payload) { + updateUser(state, payload) { state.firstName = payload.firstName state.lastName = payload.lastName state.userId = payload.userId }, - clearUser (state) { + clearUser(state) { state.firstName = '' state.lastName = '' state.userId = null - } - } + }, + }, } export default storeModule @@ -123,14 +123,14 @@ export const useAuthUserStore = defineStore('auth/user', { state: (): State => ({ firstName: '', lastName: '', - userId: null + userId: null, }), getters: { // 不在需要 firstName getter,移除 fullName: (state) => `${state.firstName} ${state.lastName}`, loggedIn: (state) => state.userId !== null, // 由于使用了 `this`,必须定义一个返回类型 - fullUserDetails (state): FullUserDetails { + fullUserDetails(state): FullUserDetails { // 导入其他 store const authPreferencesStore = useAuthPreferencesStore() const authEmailStore = useAuthEmailStore() @@ -139,7 +139,7 @@ export const useAuthUserStore = defineStore('auth/user', { // `this` 上的其他 getter fullName: this.fullName, ...authPreferencesStore.$state, - ...authEmailStore.details + ...authEmailStore.details, } // 如果其他模块仍在 Vuex 中,可替代为 @@ -149,26 +149,26 @@ export const useAuthUserStore = defineStore('auth/user', { // ...vuexStore.state.auth.preferences, // ...vuexStore.getters['auth/email'].details // } - } + }, }, actions: { //没有作为第一个参数的上下文,用 `this` 代替 - async loadUser (id: number) { + async loadUser(id: number) { if (this.userId !== null) throw new Error('Already logged in') const res = await api.user.load(id) this.updateUser(res) }, // mutation 现在可以成为 action 了,不再用 `state` 作为第一个参数,而是用 `this`。 - updateUser (payload) { + updateUser(payload) { this.firstName = payload.firstName this.lastName = payload.lastName this.userId = payload.userId }, // 使用 `$reset` 可以轻松重置 state - clearUser () { + clearUser() { this.$reset() - } - } + }, + }, }) ``` @@ -177,16 +177,16 @@ export const useAuthUserStore = defineStore('auth/user', { 1. 为 store 添加一个必要的 `id`,你可以让它与之前的命名保持相同。 2. 如果 `state` 不是一个函数的话 将它转换为一个函数。 3. 转换 `getters` - 1. 删除任何返回同名 state 的 getters (例如: `firstName: (state) => state.firstName`),这些都不是必需的,因为你可以直接从 store 实例中访问任何状态。 - 2. 如果你需要访问其他的 getter,可通过 `this` 访问它们,而不是第二个参数。记住,如果你使用 `this`,而且你不得不使用一个普通函数,而不是一个箭头函数,那么由于 TS 的限制,你需要指定一个返回类型,更多细节请阅读[这篇文档](../core-concepts/getters.md#accessing-other-getters) - 3. 如果使用 `rootState` 或 `rootGetters` 参数,可以直接导入其他 store 来替代它们,或者如果它们仍然存在于 Vuex ,则直接从 Vuex 中访问它们。 + 1. 删除任何返回同名 state 的 getters (例如: `firstName: (state) => state.firstName`),这些都不是必需的,因为你可以直接从 store 实例中访问任何状态。 + 2. 如果你需要访问其他的 getter,可通过 `this` 访问它们,而不是第二个参数。记住,如果你使用 `this`,而且你不得不使用一个普通函数,而不是一个箭头函数,那么由于 TS 的限制,你需要指定一个返回类型,更多细节请阅读[这篇文档](../core-concepts/getters.md#accessing-other-getters) + 3. 如果使用 `rootState` 或 `rootGetters` 参数,可以直接导入其他 store 来替代它们,或者如果它们仍然存在于 Vuex ,则直接从 Vuex 中访问它们。 4. 转换 `actions` - 1. 从每个 action 中删除第一个 `context` 参数。所有的东西都应该直接从 `this` 中访问。 - 2. 如果使用其他 store,要么直接导入,要么与 getters 一样,在 Vuex 上访问。 + 1. 从每个 action 中删除第一个 `context` 参数。所有的东西都应该直接从 `this` 中访问。 + 2. 如果使用其他 store,要么直接导入,要么与 getters 一样,在 Vuex 上访问。 5. 转换 `mutations` - 1. Mutation 已经被弃用了。它们可以被转换为 `action`,或者你可以在你的组件中直接赋值给 store (例如:`userStore.firstName = 'First'`) - 2. 如果你想将它转换为 action,删除第一个 `state` 参数,用 `this` 代替任何赋值操作中的 `state`。 - 3. 一个常见的 mutation 是将 state 重置为初始 state。而这就是 store 的 `$reset` 方法的内置功能。注意,这个功能只存在于 option stores。 + 1. Mutation 已经被弃用了。它们可以被转换为 `action`,或者你可以在你的组件中直接赋值给 store (例如:`userStore.firstName = 'First'`) + 2. 如果你想将它转换为 action,删除第一个 `state` 参数,用 `this` 代替任何赋值操作中的 `state`。 + 3. 一个常见的 mutation 是将 state 重置为初始 state。而这就是 store 的 `$reset` 方法的内置功能。注意,这个功能只存在于 option stores。 正如你所看到的,你的大部分代码都可以被重复使用。如果有什么遗漏,类型安全也应该可以帮助你确定需要修改的地方。 @@ -204,7 +204,7 @@ import { defineComponent, computed } from 'vue' import { useStore } from 'vuex' export default defineComponent({ - setup () { + setup() { const store = useStore() const firstName = computed(() => store.state.auth.user.firstName) @@ -212,9 +212,9 @@ export default defineComponent({ return { firstName, - fullName + fullName, } - } + }, }) ``` @@ -224,7 +224,7 @@ import { defineComponent, computed } from 'vue' import { useAuthUserStore } from '@/stores/auth-user' export default defineComponent({ - setup () { + setup() { const authUserStore = useAuthUserStore() const firstName = computed(() => authUserStore.firstName) @@ -234,9 +234,9 @@ export default defineComponent({ // 你也可以在你的组件中通过返回 store 来访问整个 store authUserStore, firstName, - fullName + fullName, } - } + }, }) ``` diff --git a/packages/docs/zh/cookbook/options-api.md b/packages/docs/zh/cookbook/options-api.md index a63b5824..3142cafe 100644 --- a/packages/docs/zh/cookbook/options-api.md +++ b/packages/docs/zh/cookbook/options-api.md @@ -27,7 +27,7 @@ export default { computed: { // 注意,我们不是在传递一个数组,而是一个接一个的 store。 // 可以 id+'Store' 的形式访问每个 store 。 - ...mapStores(useCartStore, useUserStore) + ...mapStores(useCartStore, useUserStore), }, methods: { diff --git a/packages/docs/zh/cookbook/testing.md b/packages/docs/zh/cookbook/testing.md index 29c10987..b92e9df5 100644 --- a/packages/docs/zh/cookbook/testing.md +++ b/packages/docs/zh/cookbook/testing.md @@ -113,7 +113,7 @@ expect(store.someAction).toHaveBeenLastCalledWith() ### 初始 State %{#initial-state}% -在创建测试 Pinia 时,你可以通过传递一个 `initialState` 对象来设置**所有 store 的初始状态**。这个对象将被 pinia 的测试实例用于创建 store 时 *patch* store。比方说,你想初始化这个 store 的状态: +在创建测试 Pinia 时,你可以通过传递一个 `initialState` 对象来设置**所有 store 的初始状态**。这个对象将被 pinia 的测试实例用于创建 store 时 _patch_ store。比方说,你想初始化这个 store 的状态: ```ts import { defineStore } from 'pinia' @@ -124,7 +124,7 @@ const useCounterStore = defineStore('counter', { }) ``` -由于 store 的名字是 *"counter"*,所以你需要传递相应的对象给 `initialState`: +由于 store 的名字是 _"counter"_,所以你需要传递相应的对象给 `initialState`: ```ts // 在测试中的某处 diff --git a/packages/docs/zh/core-concepts/actions.md b/packages/docs/zh/core-concepts/actions.md index 002ebb7e..e8f6fed7 100644 --- a/packages/docs/zh/core-concepts/actions.md +++ b/packages/docs/zh/core-concepts/actions.md @@ -74,7 +74,7 @@ store.randomizeCounter() ## 访问其他 store 的 action %{#accessing-other-stores-actions}% -想要使用另一个 store 的话,那你直接在 *action* 中调用就好了: +想要使用另一个 store 的话,那你直接在 _action_ 中调用就好了: ```js import { useAuthStore } from './auth-store' @@ -114,13 +114,13 @@ import { defineStore } from 'pinia' const useCounterStore = defineStore('counter', { state: () => ({ - count: 0 + count: 0, }), actions: { increment() { this.count++ - } - } + }, + }, }) ``` @@ -208,7 +208,7 @@ const unsubscribe = someStore.$onAction( unsubscribe() ``` -默认情况下,*action 订阅器*会被绑定到添加它们的组件上(如果 store 在组件的 `setup()` 内)。这意味着,当该组件被卸载时,它们将被自动删除。如果你想在组件卸载后依旧保留它们,请将 `true` 作为第二个参数传递给 *action 订阅器*,以便将其从当前组件中分离: +默认情况下,*action 订阅器*会被绑定到添加它们的组件上(如果 store 在组件的 `setup()` 内)。这意味着,当该组件被卸载时,它们将被自动删除。如果你想在组件卸载后依旧保留它们,请将 `true` 作为第二个参数传递给 _action 订阅器_,以便将其从当前组件中分离: ```vue