From: Xavi Lee Date: Thu, 2 Feb 2023 10:14:27 +0000 (+0800) Subject: docs(zh): sync with English version (#1911) X-Git-Tag: @pinia/nuxt@0.4.7~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11a649626524ae70938e191bb8c2ce0e21d96067;p=thirdparty%2Fvuejs%2Fpinia.git docs(zh): sync with English version (#1911) Co-authored-by: Yoshi Otobe <38850403+yoshiotobe@users.noreply.github.com> Co-authored-by: Eduardo San Martin Morote Co-authored-by: 林洵锋 Co-authored-by: Eduardo San Martin Morote --- diff --git a/packages/docs/.vitepress/config/zh.ts b/packages/docs/.vitepress/config/zh.ts index 60b62f88..09401268 100644 --- a/packages/docs/.vitepress/config/zh.ts +++ b/packages/docs/.vitepress/config/zh.ts @@ -22,7 +22,9 @@ export const zhConfig: LocaleSpecificConfig = { text: '对本页提出修改建议', }, - outlineTitle: '本页内容', + outline: { + label: '本页内容' + }, nav: [ // { text: 'Config', link: '/config/' }, diff --git a/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md b/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md index 60241954..bc4eeeb1 100644 --- a/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md +++ b/packages/docs/zh/api/interfaces/pinia._StoreOnActionListenerContext.md @@ -35,7 +35,7 @@ sidebarDepth: 3 action 执行完的钩子。 它接收 action 的返回值,如果是 Promise,它将被自动解包。 -##### 参数{#parameters} +##### 参数 %{#parameters}% | 名称 | 类型 | | :------ | :------ | diff --git a/packages/docs/zh/api/modules/pinia.md b/packages/docs/zh/api/modules/pinia.md index 9f95cc48..eafecd4e 100644 --- a/packages/docs/zh/api/modules/pinia.md +++ b/packages/docs/zh/api/modules/pinia.md @@ -186,7 +186,7 @@ ___ | :------ | | `S` | -#### 类型声明{#type-declaration} +#### 类型声明 %{#type-declaration}% ▸ (`mutation`, `state`): `void` @@ -285,7 +285,7 @@ ___ ___ -### \_ExtractGettersFromSetupStore{#extractgettersfromsetupstore} +### \_ExtractGettersFromSetupStore %{#extractgettersfromsetupstore}% Ƭ **\_ExtractGettersFromSetupStore**<`SS`\>: `SS` extends `undefined` \| `void` ? {} : [`_ExtractGettersFromSetupStore_Keys`](pinia.md#_extractgettersfromsetupstore_keys)<`SS`\> extends keyof `SS` ? `Pick`<`SS`, [`_ExtractGettersFromSetupStore_Keys`](pinia.md#_extractgettersfromsetupstore_keys)<`SS`\>\> : `never` @@ -314,7 +314,7 @@ ___ ___ -### \_ExtractStateFromSetupStore{#extractstatefromsetupstore} +### \_ExtractStateFromSetupStore %{#extractstatefromsetupstore}% Ƭ **\_ExtractStateFromSetupStore**<`SS`\>: `SS` extends `undefined` \| `void` ? {} : [`_ExtractStateFromSetupStore_Keys`](pinia.md#_extractstatefromsetupstore_keys)<`SS`\> extends keyof `SS` ? [`_UnwrapAll`](pinia.md#_unwrapall)<`Pick`<`SS`, [`_ExtractStateFromSetupStore_Keys`](pinia.md#_extractstatefromsetupstore_keys)<`SS`\>\>\> : `never` @@ -328,7 +328,7 @@ ___ ___ -### \_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 } @@ -545,7 +545,7 @@ ___ | :------ | | `SS` | -## 变量{#variables} +## 变量 %{#variables}% ### PiniaVuePlugin %{#piniavueplugin}% @@ -1137,7 +1137,7 @@ ___ 默认为`"Store"`。如果你需要使用 TypeScript, 请确保扩展 MapStoresCustomization 接口。 -#### 参数{#parameters} +#### 参数 %{#parameters}% | 名称 | 类型 | 描述 | | :------ | :------ | :------ | diff --git a/packages/docs/zh/cookbook/migration-v1-v2.md b/packages/docs/zh/cookbook/migration-v1-v2.md index 50418e57..91d6848f 100644 --- a/packages/docs/zh/cookbook/migration-v1-v2.md +++ b/packages/docs/zh/cookbook/migration-v1-v2.md @@ -36,43 +36,41 @@ yarn add 'pinia@^2.x.x' 添加于 [2.0.0-rc.0](https://github.com/vuejs/pinia/blob/v2/packages/pinia/CHANGELOG.md#200-rc0-2021-07-28) -用 `StoreGeneric` 取代 `GenericStore` 类型的全部用法。这是新的通用 store 类型,应该可以接受任何类型的 store。如果你在写函数时使用 `Store` 类型而不想传递其泛型(例如`Store`),你可以使用 `StoreGeneric`,因为没有泛型的 `Store` 类型会创建一个空的 store 类型: +用 `StoreGeneric` 取代 `GenericStore` 类型的全部用法。这是新的通用 store 类型,应该可以接受任何类型的 store。如果你在写函数时使用 `Store` 类型而不想传递其泛型 (例如`Store`),你可以使用 `StoreGeneric`,因为没有泛型的 `Store` 类型会创建一个空的 store 类型: -```diff --function takeAnyStore(store: Store) {} -+function takeAnyStore(store: StoreGeneric) {} - --function takeAnyStore(store: GenericStore) {} -+function takeAnyStore(store: StoreGeneric) {} +```ts +function takeAnyStore(store: Store) {} // [!code --] +function takeAnyStore(store: StoreGeneric) {} // [!code ++] +function takeAnyStore(store: GenericStore) {} // [!code --] +function takeAnyStore(store: StoreGeneric) {} // [!code ++] ``` ## 针对插件的 `DefineStoreOptions` %{#definestoreoptions-for-plugins}% 如果你在用 TypeScript 写插件并扩展了 `DefineStoreOptions` 类型来添加自定义选项,你应该把它改名为 `DefineStoreOptionsBase`。这个类型将同时适用于 setup 和 option store。 -```diff - declare module 'pinia' { -- export interface DefineStoreOptions { -+ export interface DefineStoreOptionsBase { - debounce?: { - [k in keyof StoreActions]?: number - } - } - } +```ts +declare module 'pinia' { + export interface DefineStoreOptions { // [!code --] + export interface DefineStoreOptionsBase { // [!code ++] + debounce?: { + [k in keyof StoreActions]?: number + } + } +} ``` ## `PiniaStorePlugin` 已被重命名 %{#piniastoreplugin-was-renamed}% 类型 `PiniaStorePlugin` 被重新命名为 `PiniaPlugin`。 -```diff --import { PiniaStorePlugin } from 'pinia' -+import { PiniaPlugin } from 'pinia' - --const piniaPlugin: PiniaStorePlugin = () => { -+const piniaPlugin: PiniaPlugin = () => { - // ... - } +```ts +import { PiniaStorePlugin } from 'pinia' // [!code --] +import { PiniaPlugin } from 'pinia' // [!code ++] +const piniaPlugin: PiniaStorePlugin = () => { // [!code --] +const piniaPlugin: PiniaPlugin = () => { // [!code ++] + // ... +} ``` **注意这个更新只能在升级到最新的没有弃用的 Pinia 版本后生效**。 @@ -89,7 +87,7 @@ yarn add @vue/composition-api@latest ## 支持 webpack 4 %{#webpack-4-support}% -如果你使用的是 webpack 4(Vue CLI 使用的是 webpack 4),你可能会遇到这样的错误: +如果你使用的是 webpack 4 (Vue CLI 使用的是 webpack 4),你可能会遇到这样的错误: ``` ERROR Failed to compile with 18 errors @@ -146,7 +144,7 @@ Pinia v2 不再劫持 Vue Devtools v5,它需要的是 Vue Devtools v6。可以 如果你正在使用 Nuxt,pinia 现在有了专门的 Nuxt 软件包🎉。请用以下方法安装它: -```shell +```bash npm i @pinia/nuxt # 或者使用 yarn yarn add @pinia/nuxt @@ -156,26 +154,26 @@ yarn add @pinia/nuxt 如果你使用 TypeScript,还要调整你的 `nuxt.config.js` 和 `tsconfig.json`: -```diff - // nuxt.config.js - module.exports { - buildModules: [ - '@nuxtjs/composition-api/module', -- 'pinia/nuxt', -+ '@pinia/nuxt', - ], - } +```js +// nuxt.config.js +module.exports { + buildModules: [ + '@nuxtjs/composition-api/module', + 'pinia/nuxt', // [!code --] + '@pinia/nuxt', // [!code ++] + ], +} ``` -```diff - // tsconfig.json - { - "types": [ - // ... -- "pinia/nuxt/types" -+ "@pinia/nuxt" - ] - } +```json +// tsconfig.json +{ + "types": [ + // ... + "pinia/nuxt/types" // [!code --] + "@pinia/nuxt" // [!code ++] + ] +} ``` [Nuxt 专属章节](../ssr/nuxt.md)也值得一读。 diff --git a/packages/docs/zh/core-concepts/actions.md b/packages/docs/zh/core-concepts/actions.md index 855666c4..97e5f6f4 100644 --- a/packages/docs/zh/core-concepts/actions.md +++ b/packages/docs/zh/core-concepts/actions.md @@ -23,7 +23,7 @@ export const useStore = defineStore('main', { }) ``` -类似 [getter](./getters.md),action 也可通过 `this` 访问**整个 store 实例**,并支持**完整的类型标注(以及自动补全✨)**。**不同的是,`action` 可以是异步的**,你可以在它们里面 `await` 调用任何 API,以及其他 action!下面是一个使用 [Mande](https://github.com/posva/mande) 的例子。请注意,你使用什么库并不重要,只要你得到的是一个`Promise`,你甚至可以(在浏览器中)使用原生 `fetch` 函数: +类似 [getter](./getters.md),action 也可通过 `this` 访问**整个 store 实例**,并支持**完整的类型标注(以及自动补全✨)**。**不同的是,`action` 可以是异步的**,你可以在它们里面 `await` 调用任何 API,以及其他 action!下面是一个使用 [Mande](https://github.com/posva/mande) 的例子。请注意,你使用什么库并不重要,只要你得到的是一个`Promise`,你甚至可以 (在浏览器中) 使用原生 `fetch` 函数: ```js import { mande } from 'mande' @@ -53,18 +53,18 @@ export const useUsers = defineStore('users', { 你也完全可以自由地设置任何你想要的参数以及返回任何结果。当调用 action 时,一切类型也都是可以被自动推断出来的。 -Action 可以像方法一样被调用: - -```js -export default defineComponent({ - setup() { - const main = useMainStore() - // 作为 store 的一个方法调用该 action - main.randomizeCounter() - - return {} - }, -}) +Action 可以像函数或者通常意义上的方法一样被调用: + +```vue + + ``` ## 访问其他 store 的 action %{#accessing-other-stores-actions}% @@ -92,20 +92,6 @@ export const useSettingsStore = defineStore('settings', { }) ``` -## 使用 `setup()` 时的用法 %{#usage-with-setup}% - -你可以将任何 action 作为 store 的一个方法直接调用: - -```js -export default { - setup() { - const store = useStore() - - store.randomizeCounter() - }, -} -``` - ## 使用选项式 API 的用法 %{#usage-with-the-options-api}% import { useCounterStore } from '../stores/counter' - -export default { +export default defineComponent({ setup() { const counterStore = useCounterStore() - return { counterStore } }, methods: { @@ -152,7 +137,8 @@ export default { console.log('New Count:', this.counterStore.count) }, }, -} +}) + ``` ### 不使用 `setup()` %{#without-setup}% @@ -219,15 +205,10 @@ unsubscribe() 默认情况下,*action 订阅器*会被绑定到添加它们的组件上(如果 store 在组件的 `setup()` 内)。这意味着,当该组件被卸载时,它们将被自动删除。如果你想在组件卸载后依旧保留它们,请将 `true` 作为第二个参数传递给 *action 订阅器*,以便将其从当前组件中分离: -```js -export default { - setup() { - const someStore = useSomeStore() - - // 在组件被卸载后,这个订阅依旧会被保留。 - someStore.$onAction(callback, true) - - // ... - }, -} +```vue + ``` diff --git a/packages/docs/zh/core-concepts/getters.md b/packages/docs/zh/core-concepts/getters.md index 94113f0b..19018cd6 100644 --- a/packages/docs/zh/core-concepts/getters.md +++ b/packages/docs/zh/core-concepts/getters.md @@ -42,19 +42,13 @@ export const useStore = defineStore('main', { 然后你可以直接访问 store 实例上的 getter 了: ```vue + - - ``` ## 访问其他 getter %{#accessing-other-getters}% @@ -101,14 +95,12 @@ export const useStore = defineStore('main', { 并在组件中使用: ```vue -