From bea6ed1d9c969a58053bbbceafa12c09d30d6d24 Mon Sep 17 00:00:00 2001 From: Mahdi Shah Abbasian Date: Tue, 18 Jul 2023 14:01:45 +0330 Subject: [PATCH] docs: standardize indentation and tag positioning (#22157) --- docs/1.getting-started/3.configuration.md | 4 +- docs/1.getting-started/4.styling.md | 18 +++-- docs/1.getting-started/5.routing.md | 6 +- docs/1.getting-started/5.seo-meta.md | 10 +-- docs/1.getting-started/6.data-fetching.md | 27 +++---- docs/1.getting-started/7.state-management.md | 6 +- docs/1.getting-started/8.error-handling.md | 12 +-- docs/2.guide/1.concepts/1.auto-imports.md | 22 +++--- .../2.guide/1.concepts/2.vuejs-development.md | 6 +- .../2.directory-structure/1.components.md | 34 ++++----- .../2.directory-structure/1.composables.md | 8 +- .../2.directory-structure/1.layouts.md | 36 ++++----- .../2.directory-structure/1.middleware.md | 4 +- docs/2.guide/2.directory-structure/1.pages.md | 12 +-- .../2.directory-structure/1.plugins.md | 10 +-- .../2.guide/2.directory-structure/1.server.md | 16 ++-- .../3.going-further/10.runtime-config.md | 14 ++-- docs/2.guide/3.going-further/2.hooks.md | 6 +- docs/3.api/1.composables/use-cookie.md | 40 +++++----- .../1.composables/use-lazy-async-data.md | 14 ++-- docs/3.api/1.composables/use-lazy-fetch.md | 22 +++--- docs/3.api/1.composables/use-nuxt-app.md | 6 +- .../1.composables/use-request-headers.md | 2 +- docs/3.api/1.composables/use-request-url.md | 2 +- docs/3.api/1.composables/use-route.md | 2 +- docs/3.api/2.components/2.nuxt-page.md | 10 +-- docs/3.api/2.components/3.nuxt-layout.md | 18 ++--- docs/3.api/3.utils/$fetch.md | 4 +- docs/3.api/3.utils/create-error.md | 2 +- docs/3.api/3.utils/define-page-meta.md | 74 +++++++++---------- docs/3.api/3.utils/navigate-to.md | 6 +- docs/3.api/3.utils/refresh-nuxt-data.md | 28 +++---- docs/6.bridge/1.overview.md | 2 +- docs/7.migration/4.meta.md | 2 +- docs/7.migration/6.pages-and-layouts.md | 4 +- docs/7.migration/7.component-options.md | 12 +-- docs/7.migration/8.runtime-config.md | 8 +- 37 files changed, 257 insertions(+), 252 deletions(-) diff --git a/docs/1.getting-started/3.configuration.md b/docs/1.getting-started/3.configuration.md index 21dba96333..c42aa152d8 100644 --- a/docs/1.getting-started/3.configuration.md +++ b/docs/1.getting-started/3.configuration.md @@ -81,7 +81,7 @@ NUXT_API_SECRET=api_secret_token These variables are exposed to the rest of your application using the [`useRuntimeConfig`](/docs/api/composables/use-runtime-config) composable. ```vue [pages/index.vue] - ``` @@ -109,7 +109,7 @@ export default defineAppConfig({ These variables are exposed to the rest of your application using the [`useAppConfig`](/docs/api/composables/use-app-config) composable. ```vue [pages/index.vue] - ``` diff --git a/docs/1.getting-started/4.styling.md b/docs/1.getting-started/4.styling.md index 33b9e356b3..9178f331a9 100644 --- a/docs/1.getting-started/4.styling.md +++ b/docs/1.getting-started/4.styling.md @@ -255,7 +255,7 @@ You can leverage Vue SFC features to style your components with class and style ::code-group ```vue [Ref and Reactive] - -
-
+ + ``` ```vue [Computed] - + ``` ```vue [Array] - @@ -294,7 +298,7 @@ const errorClass = ref('text-danger') ``` ```vue [Style] - diff --git a/docs/1.getting-started/5.routing.md b/docs/1.getting-started/5.routing.md index 8949768911..9209b85255 100644 --- a/docs/1.getting-started/5.routing.md +++ b/docs/1.getting-started/5.routing.md @@ -72,7 +72,7 @@ When a `` enters the viewport on the client side, Nuxt will automatica The `useRoute()` composable can be used in a ` @@ -161,7 +161,7 @@ It's recommended to use getters (`() => value`) over computed (`computed(() => v ``` ```vue [Components] - @@ -227,7 +227,7 @@ Within your [`pages/` directory](/docs/guide/directory-structure/pages), you can For example, you can first set the current page title (this is extracted at build time via a macro, so it can't be set dynamically): ```vue{}[pages/some-page.vue] - @@ -116,6 +116,12 @@ The first argument of [`useAsyncData`](/docs/api/composables/use-async-data) is By default, data fetching composables will wait for the resolution of their asynchronous function before navigating to a new page by using Vue’s Suspense. This feature can be ignored on client-side navigation with the `lazy` option. In that case, you will have to manually handle loading state using the `pending` value. ```vue [app.vue] + + - ``` You can alternatively use [`useLazyFetch`](/docs/api/composables/use-lazy-fetch) and `useLazyAsyncData` as convenient methods to perform the same. @@ -163,7 +164,7 @@ const { pending, data: posts } = useFetch('/api/comments', { The `pick` option helps you to minimize the payload size stored in your HTML document by only selecting the fields that you want returned from the composables. ```vue - @@ -202,15 +203,15 @@ To get the cached data by key, you can use [`useNuxtData`](/docs/api/composables If you want to fetch or refresh data manually, use the `execute` or `refresh` function provided by the composables. (`execute` is an alias for `refresh` that works in exactly the same way but is more semantic for cases when `immediate: false`). ```vue - ``` @@ -242,7 +243,7 @@ We can use [`useRequestHeaders`](/docs/api/composables/use-request-headers) to a The example below adds the request headers to an isomorphic `$fetch` call to ensure that the API endpoint has access to the same `cookie` header originally sent by the user. ```vue - diff --git a/docs/1.getting-started/7.state-management.md b/docs/1.getting-started/7.state-management.md index 16f8150fbe..249971fa2b 100644 --- a/docs/1.getting-started/7.state-management.md +++ b/docs/1.getting-started/7.state-management.md @@ -36,7 +36,7 @@ Instead use `const useX = () => useState('x')` In this example, we use a component-local counter state. Any other component that uses `useState('counter')` shares the same reactive state. ```vue [app.vue] - @@ -108,7 +108,7 @@ export const useLocaleDate = (date: Ref | Date, locale = useLocale()) => { ``` ```vue [app.vue] - diff --git a/docs/1.getting-started/8.error-handling.md b/docs/1.getting-started/8.error-handling.md index 559fbf3e71..c7f751f919 100644 --- a/docs/1.getting-started/8.error-handling.md +++ b/docs/1.getting-started/8.error-handling.md @@ -74,17 +74,17 @@ If you are running on Node 16 and you set any cookies when rendering your error ### Example ```vue [error.vue] - - - + + ``` ## Error Helper Methods @@ -112,7 +112,7 @@ If you throw an error created with `createError`: ### Example ```vue [pages/movies/[slug].vue] - ``` @@ -41,10 +41,10 @@ Nuxt auto-imports functions and composables to perform [data fetching](/docs/get Vue 3 exposes Reactivity APIs like `ref` or `computed`, as well as lifecycle hooks and helpers that are auto-imported by Nuxt. ```vue - ``` @@ -103,11 +103,11 @@ Nuxt directly auto-imports files created in defined directories: Nuxt exposes every auto-import with the `#imports` alias that can be used to make the import explicit if needed: ```vue - ``` diff --git a/docs/2.guide/1.concepts/2.vuejs-development.md b/docs/2.guide/1.concepts/2.vuejs-development.md index dc48f31179..8209ee832f 100644 --- a/docs/2.guide/1.concepts/2.vuejs-development.md +++ b/docs/2.guide/1.concepts/2.vuejs-development.md @@ -94,9 +94,9 @@ The [Composition API](https://vuejs.org/guide/extras/composition-api-faq.html) i Used with the `setup` keyword in the ` ``` diff --git a/docs/2.guide/2.directory-structure/1.components.md b/docs/2.guide/2.directory-structure/1.components.md index 23fed003f2..df310e6809 100644 --- a/docs/2.guide/2.directory-structure/1.components.md +++ b/docs/2.guide/2.directory-structure/1.components.md @@ -103,13 +103,13 @@ If you want to use the Vue `` syntax, the For example: ```vue + + - - ``` ::alert{type=warning} @@ -150,14 +150,6 @@ To dynamically import a component (also known as lazy-loading a component) all y This is particularly useful if the component is not always needed. By using the `Lazy` prefix you can delay loading the component code until the right moment, which can be helpful for optimizing your JavaScript bundle size. ```html [pages/index.vue] - - + + ``` ## Direct Imports @@ -174,6 +174,11 @@ export default { You can also explicitly import components from `#components` if you want or need to bypass Nuxt's auto-importing functionality. ```html [pages/index.vue] + + - - ``` ## `` Component diff --git a/docs/2.guide/2.directory-structure/1.composables.md b/docs/2.guide/2.directory-structure/1.composables.md index 0131014dc4..102f22e826 100644 --- a/docs/2.guide/2.directory-structure/1.composables.md +++ b/docs/2.guide/2.directory-structure/1.composables.md @@ -35,15 +35,15 @@ export default function () { **Usage:** You can now use auto imported composable in `.js`, `.ts` and `.vue` files ```vue [app.vue] + + - - ``` ::LinkExample{link="/docs/examples/features/auto-imports"} diff --git a/docs/2.guide/2.directory-structure/1.layouts.md b/docs/2.guide/2.directory-structure/1.layouts.md index 6178270b22..f6d961d08b 100644 --- a/docs/2.guide/2.directory-structure/1.layouts.md +++ b/docs/2.guide/2.directory-structure/1.layouts.md @@ -53,16 +53,16 @@ If you use a `app.vue` you will also need to add ``: You can directly override the default layout like this: ```vue{}[app.vue] + + - - ``` Alternatively, you can override the default layout per-page like this: @@ -115,13 +115,7 @@ Learn more about [defining page meta](/docs/guide/directory-structure/pages#page You can also use a ref or computed property for your layout. ```vue - - - + + ``` ::LinkExample{link="/docs/examples/features/layouts"} @@ -141,6 +141,12 @@ If you are using the `~/pages` integration, you can take full control by setting ::code-group ```vue [pages/index.vue] + + - - ``` ```vue [layouts/custom.vue] diff --git a/docs/2.guide/2.directory-structure/1.middleware.md b/docs/2.guide/2.directory-structure/1.middleware.md index 0bf7036db0..5520b4eaa9 100644 --- a/docs/2.guide/2.directory-structure/1.middleware.md +++ b/docs/2.guide/2.directory-structure/1.middleware.md @@ -80,7 +80,7 @@ middleware/ ``` ```vue [pages/profile.vue] - + - - ``` ## Typing Plugins diff --git a/docs/2.guide/2.directory-structure/1.server.md b/docs/2.guide/2.directory-structure/1.server.md index 02b72bcd9e..8a97899438 100644 --- a/docs/2.guide/2.directory-structure/1.server.md +++ b/docs/2.guide/2.directory-structure/1.server.md @@ -29,7 +29,7 @@ export default defineEventHandler((event) => { You can now universally call this API in your pages and components: ```vue [pages/index.vue] - @@ -424,13 +424,6 @@ export default defineEventHandler(async (event) => { Create a new file in `app.vue`: ```vue [app.vue] - - + + ``` ::ReadMore{link="/docs/guide/directory-structure/server"} diff --git a/docs/2.guide/3.going-further/10.runtime-config.md b/docs/2.guide/3.going-further/10.runtime-config.md index ce70095ed9..d9c76dc972 100644 --- a/docs/2.guide/3.going-further/10.runtime-config.md +++ b/docs/2.guide/3.going-further/10.runtime-config.md @@ -91,19 +91,19 @@ Within the Vue part of your Nuxt app, you will need to call `useRuntimeConfig()` The entire runtime config is available on the server-side, but it is read-only to avoid context sharing. ```vue - - - + + ``` **🛑 Security note:** Be careful not to expose runtime config keys to the client-side by either rendering them or passing them to `useState`. diff --git a/docs/2.guide/3.going-further/2.hooks.md b/docs/2.guide/3.going-further/2.hooks.md index 8a36e33111..d850c1d4a8 100644 --- a/docs/2.guide/3.going-further/2.hooks.md +++ b/docs/2.guide/3.going-further/2.hooks.md @@ -41,9 +41,9 @@ App hooks can be mainly used by [Nuxt Plugins](/docs/guide/directory-structure/p ```js [plugins/test.ts] export default defineNuxtPlugin((nuxtApp) => { - nuxtApp.hook('page:start', () => { - /* your code goes here */ - }) + nuxtApp.hook('page:start', () => { + /* your code goes here */ + }) }) ``` diff --git a/docs/3.api/1.composables/use-cookie.md b/docs/3.api/1.composables/use-cookie.md index 4a69032bd7..7cc84dbf26 100644 --- a/docs/3.api/1.composables/use-cookie.md +++ b/docs/3.api/1.composables/use-cookie.md @@ -23,6 +23,11 @@ const cookie = useCookie(name, options) The example below creates a cookie called `counter`. If the cookie doesn't exist, it is initially set to a random value. Whenever we update the `counter` variable, the cookie will be updated accordingly. ```vue + + - - ``` :button-link[Open on StackBlitz]{href="https://stackblitz.com/github/nuxt/examples/tree/main/advanced/use-cookie?terminal=dev&file=app.vue" blank} @@ -143,11 +143,7 @@ Specifies the `boolean` or `string` value for [watch](https://vuejs.org/api/reac **Example 1:** ```vue - - - + + ``` **Example 2:** ```vue - - - + + ``` ## Handling Cookies in API Routes diff --git a/docs/3.api/1.composables/use-lazy-async-data.md b/docs/3.api/1.composables/use-lazy-async-data.md index bb6f14da62..ed96635962 100644 --- a/docs/3.api/1.composables/use-lazy-async-data.md +++ b/docs/3.api/1.composables/use-lazy-async-data.md @@ -17,13 +17,7 @@ By default, [useAsyncData](/docs/api/composables/use-async-data) blocks navigati ## Example ```vue - - - + + ``` ::alert{type=warning} diff --git a/docs/3.api/1.composables/use-lazy-fetch.md b/docs/3.api/1.composables/use-lazy-fetch.md index 35d9fdaf2b..c79f9be1b5 100644 --- a/docs/3.api/1.composables/use-lazy-fetch.md +++ b/docs/3.api/1.composables/use-lazy-fetch.md @@ -17,6 +17,17 @@ By default, [useFetch](/docs/api/composables/use-fetch) blocks navigation until ## Example ```vue + + - - ``` ::alert{type=warning} diff --git a/docs/3.api/1.composables/use-nuxt-app.md b/docs/3.api/1.composables/use-nuxt-app.md index 4ef42e38e3..f12d562a75 100644 --- a/docs/3.api/1.composables/use-nuxt-app.md +++ b/docs/3.api/1.composables/use-nuxt-app.md @@ -5,8 +5,8 @@ You can use `useNuxtApp()` within composables, plugins and components. ```vue [app.vue] - ``` @@ -90,7 +90,7 @@ await nuxtApp.callHook('my-plugin:init') - **data** (object) - When you fetch the data from an API endpoint using either [`useFetch`](/docs/api/composables/use-fetch) or [`useAsyncData`](/docs/api/composables/use-async-data) , resulting payload can be accessed from the `payload.data`. This data is cached and helps you prevent fetching the same data in case an identical request is made more than once. ```vue [app.vue] - ``` diff --git a/docs/3.api/1.composables/use-request-headers.md b/docs/3.api/1.composables/use-request-headers.md index ecd4e5448d..7a89b69f07 100644 --- a/docs/3.api/1.composables/use-request-headers.md +++ b/docs/3.api/1.composables/use-request-headers.md @@ -26,7 +26,7 @@ We can use [`useRequestHeaders`](/docs/api/composables/use-request-headers) to a The example below adds the `authorization` request header to an isomorphic `$fetch` call. ```vue [pages/some-page.vue] - diff --git a/docs/3.api/1.composables/use-route.md b/docs/3.api/1.composables/use-route.md index 1dab49fd34..bdfa19b143 100644 --- a/docs/3.api/1.composables/use-route.md +++ b/docs/3.api/1.composables/use-route.md @@ -14,7 +14,7 @@ Within the template of a Vue component, you can access the route using `$route`. In the following example, we call an API via [`useFetch`](/docs/api/composables/use-fetch) using a dynamic page parameter - `slug` - as part of the URL. ```html [~/pages/[slug].vue] - diff --git a/docs/3.api/2.components/2.nuxt-page.md b/docs/3.api/2.components/2.nuxt-page.md index 6a89caeff2..19b5878b7b 100644 --- a/docs/3.api/2.components/2.nuxt-page.md +++ b/docs/3.api/2.components/2.nuxt-page.md @@ -37,7 +37,7 @@ For example, passing `static` key, `NuxtPage` component is rendered only once wh Alternatively, `pageKey` can be passed as a `key` value via `definePageMeta` from the ` + + ```` ## Custom Props diff --git a/docs/3.api/2.components/3.nuxt-layout.md b/docs/3.api/2.components/3.nuxt-layout.md index 607d272408..f408d0da5d 100644 --- a/docs/3.api/2.components/3.nuxt-layout.md +++ b/docs/3.api/2.components/3.nuxt-layout.md @@ -23,16 +23,16 @@ You can use `` component to activate `default` layout on `app.vue` ### Examples ```vue [pages/index.vue] + + - - ``` ::alert{icon=👉} @@ -66,16 +66,16 @@ Please note the layout name is normalized to kebab-case, so if your layout file To get the ref of a layout component, access it through `ref.value.layoutRef` ````html - - + + ```` ::ReadMore{link="/docs/guide/directory-structure/layouts"} diff --git a/docs/3.api/3.utils/$fetch.md b/docs/3.api/3.utils/$fetch.md index dbe5df6a69..c780897eee 100644 --- a/docs/3.api/3.utils/$fetch.md +++ b/docs/3.api/3.utils/$fetch.md @@ -14,7 +14,7 @@ However, using `$fetch` in components without wrapping it with [`useAsyncData`]( We recommend to use [`useFetch`](https://nuxt.com/docs/api/composables/use-fetch) or [`useAsyncData`](https://nuxt.com/docs/api/composables/use-async-data) + `$fetch` to prevent double data fetching when fetching the component data. ```vue - ``` @@ -115,16 +115,16 @@ The example below demonstrates: - adding `pageType` as a custom property: ```vue [pages/some-page.vue] - ``` @@ -133,28 +133,28 @@ The example below demonstrates: The example below shows how the middleware can be defined using a `function` directly within the `definePageMeta` or set as a `string` that matches the middleware file name located in the `middleware/` directory: ```vue [pages/some-page.vue] - ``` @@ -164,13 +164,13 @@ The example below shows how the middleware can be defined using a `function` dir You can define the layout that matches the layout's file name located (by default) in the [`layouts/` directory](/docs/guide/directory-structure/layouts). You can also disable the layout by setting the `layout` to `false`: ```vue [pages/some-page.vue] - ``` diff --git a/docs/3.api/3.utils/navigate-to.md b/docs/3.api/3.utils/navigate-to.md index 4249df62bd..e2dc246e91 100644 --- a/docs/3.api/3.utils/navigate-to.md +++ b/docs/3.api/3.utils/navigate-to.md @@ -127,7 +127,7 @@ An object accepting the following properties: ### Navigating Within a Vue Component ```vue - + + ``` ### Refresh Specific Data @@ -54,17 +54,17 @@ const refreshAll = async () => { This example below refreshes only data where the key matches to `count`. ```vue [pages/some-page.vue] + + - - ``` ::ReadMore{link="/docs/getting-started/data-fetching"} diff --git a/docs/6.bridge/1.overview.md b/docs/6.bridge/1.overview.md index 4331447419..704fe3717b 100644 --- a/docs/6.bridge/1.overview.md +++ b/docs/6.bridge/1.overview.md @@ -260,7 +260,7 @@ Nuxt Bridge does not support `definePageMeta`. Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new [`useHead`](/docs/api/composables/use-head) composable. ```vue - ``` @@ -136,7 +136,7 @@ The validate hook in Nuxt 3 only accepts a single argument, the `route`. Just as This is not supported in Nuxt 3. Instead, you can directly use a watcher to trigger refetching data. ```vue [pages/users/[id].vue] - ```