diff --git a/docs/.gitignore b/docs/.gitignore index cc46f5e6e8..b4a500fb84 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,2 +1,2 @@ schema -*.nuxt.config.md +**/*.configuration/nuxt.config.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000000..007b17fc7a --- /dev/null +++ b/docs/README.md @@ -0,0 +1,4 @@ +# Nuxt 3 Docs + +- Website: https://v3.nuxtjs.org/ +- Setup and Contribution Guide: https://v3.nuxtjs.org/community/contribution#documentation-guide diff --git a/docs/assets/nuxt.css b/docs/assets/nuxt.css index 1cb8f98642..26cbe0958d 100644 --- a/docs/assets/nuxt.css +++ b/docs/assets/nuxt.css @@ -24,3 +24,7 @@ button:focus-visible, div:focus-visible, a:focus-visible { border-radius: 2px; box-shadow: 0 0 0 2px #00DC82; } + +h1 > code, h2 > code, h3 > code, h4 > code, h5 > code, h6 > code { + font-size: inherit !important; +} diff --git a/docs/components/templates/AutoGenerated.vue b/docs/components/templates/AutoGenerated.vue new file mode 100644 index 0000000000..4eb0c5de15 --- /dev/null +++ b/docs/components/templates/AutoGenerated.vue @@ -0,0 +1,8 @@ + + + diff --git a/docs/components/templates/NeedContribution.vue b/docs/components/templates/NeedContribution.vue new file mode 100644 index 0000000000..2468444655 --- /dev/null +++ b/docs/components/templates/NeedContribution.vue @@ -0,0 +1,11 @@ + + + diff --git a/docs/components/templates/ReadMore.vue b/docs/components/templates/ReadMore.vue new file mode 100644 index 0000000000..666d5a16a0 --- /dev/null +++ b/docs/components/templates/ReadMore.vue @@ -0,0 +1,30 @@ + + + diff --git a/docs/content/1.getting-started/1.introduction.md b/docs/content/1.getting-started/1.introduction.md deleted file mode 100644 index ab2e1d8070..0000000000 --- a/docs/content/1.getting-started/1.introduction.md +++ /dev/null @@ -1,95 +0,0 @@ -# Introduction - -Getting started with Nuxt 3 is straightforward. - -::alert{type=warning icon=🚧} -Nuxt 3 is currently in beta, keep in mind that **it is not yet production-ready**.
-Thank you in advance for your understanding πŸ’› Check out the [roadmap](/community/roadmap) for more info. -:: - -## What is Nuxt? - -If this is the first time you're learning about Nuxt or you want to get more familiar with Nuxt 3, we recommend you begin by reading the [Concepts section](/concepts). - -## Prerequisites - -Before getting started, please make sure you have installed the recommended setup. - -* **Node.js*** (latest LTS version) πŸ‘‰ [[Download](https://nodejs.org/en/download/)] -* **Visual Studio Code** πŸ‘‰ [[Download](https://code.visualstudio.com/)] -* **Volar Extension** πŸ‘‰ [[Download](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)] - * Either enable [**Take Over Mode**](https://github.com/johnsoncodehk/volar/discussions/471) (recommended) - * ... or add **TypeScript Vue Plugin (Volar)** πŸ‘‰ [[Download](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin)] - -* If you already have Node.js installed, check with `node --version` that you are using `v14` or `v16`. - -::alert{type=info} - -If you have enabled **Take Over Mode** or installed the **TypeScript Vue Plugin (Volar)** you can disable generating the shim for `*.vue` files: - -```js -export default defineNuxtConfig({ - typescript: { - shim: false - } -}) -``` - -:: - -## Nuxt 3 or Bridge? - -Next, decide whether to start from scratch or upgrade an existing Nuxt 2 project. - -### Starting a fresh Nuxt project - -::list{type=info} - -* Enjoy using Vue 3 -* All the new composables are available -* New templating system and conventions are enabled -:: - -::alert{icon=πŸ‘‰} -Checkout the [Installation section](/getting-started/installation). -:: - -### Migrating a Nuxt 2 project - -If you have an existing Nuxt 2 project, we **strongly recommend** you begin by using Nuxt Bridge. This way you can try most new features while keeping breaking changes to a minimum. - -::list{type=info} - -* It's risk-free! You can always remove the module from your config -* Makes your project (almost) ready for Nuxt 3 -* Enjoy new DX improvements without major rewrites for Vue 3 -* Use Nitro engine for platform-agnostic and optimized deployments -* Help us stabilize Nuxt 3 and discover flaws -* Nuxt Bridge is more stable than Nuxt 3 at the moment -:: - -::alert{icon=πŸ‘‰} -Checkout the [Bridge installation section](/getting-started/bridge). -:: - -### ‍Comparison - -In the table below, there is a quick comparison between 3 versions of Nuxt: - -Feature / Version | Nuxt 2 | Nuxt Bridge | Nuxt 3 --------------------------|-----------------|------------------|--------- -Vue | 2 | 2 | 3 -Stability | 😊 Stable | 😌 Semi-stable | 😬 Unstable -Performance | 🏎 Fast | ✈️ Faster | πŸš€ Fastest -Nitro Engine | ❌ | βœ… | βœ… -ESM support | πŸŒ™ Partial | πŸ‘ Better | βœ… -TypeScript | β˜‘οΈ Opt-in | 🚧 Partial | βœ… -Composition API | ❌ | 🚧 Partial | βœ… -Options API | βœ… | βœ… | βœ… -Components Auto Import | βœ… | βœ… | βœ… -` ``` -## Isomorphic fetch +## Isomorphic `fetch` and `$fetch` When we call `fetch` in the browser, user headers like `cookie` will be directly sent to the API. But during server-side-rendering, since the `fetch` request takes place 'internally' within the server, it doesn't include the user's browser cookies, nor does it pass on cookies from the fetch response. +::ReadMore{link="/api/utils/$fetch"} +:: + ### Example: Bypass API headers to client -We can use [`useRequestHeaders`](/docs/usage/ssr) to access and proxy cookies to the API from server-side. +We can use [`useRequestHeaders`](/api/composables/use-request-headers) to access and proxy cookies to the API from server-side. 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. diff --git a/docs/content/3.docs/1.usage/2.state.md b/docs/content/2.guide/2.features/6.state-management.md similarity index 81% rename from docs/content/3.docs/1.usage/2.state.md rename to docs/content/2.guide/2.features/6.state-management.md index e71cf5ba81..33f5e4b8fd 100644 --- a/docs/content/3.docs/1.usage/2.state.md +++ b/docs/content/2.guide/2.features/6.state-management.md @@ -1,18 +1,11 @@ -# State +# State Management Nuxt provides `useState` composable to create a reactive and SSR-friendly shared state across components. `useState` is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core.html#ref) replacement. Its value will be preserved after server-side rendering (during client-side hydration) and shared across all components using a unique key. -## Signature - -```ts -useState(key: string, init?: () => T): Ref -``` - -* **key**: A unique key ensuring that data fetching can be properly de-duplicated across requests -* **init**: A function that provides initial value for the state when it's not initiated -* **T**: (typescript only) Specify the type of state +::ReadMore{link="/api/composables/use-state"} +:: ::alert{icon=πŸ‘‰} `useState` only works during `setup` or [`Lifecycle Hooks`](https://vuejs.org/api/composition-api-lifecycle.html#composition-api-lifecycle-hooks). @@ -54,6 +47,9 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000)) :button-link[Open on StackBlitz]{href="https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-state?terminal=dev" blank} +::ReadMore{link="/api/composables/use-state"} +:: + ### Advanced In this example, we use a composable that detects the user's default locale from the HTTP request headers and keeps it in a `locale` state. @@ -62,7 +58,7 @@ In this example, we use a composable that detects the user's default locale from ## Shared state -By using [auto-imported composables](/docs/directory-structure/composables) we can define global type-safe states and import them across the app. +By using [auto-imported composables](/guide/directory-structure/composables) we can define global type-safe states and import them across the app. ```ts [composables/states.ts] export const useCounter = () => useState('counter', () => 0) diff --git a/docs/content/3.docs/1.usage/8.error-handling.md b/docs/content/2.guide/2.features/7.error-handling.md similarity index 93% rename from docs/content/3.docs/1.usage/8.error-handling.md rename to docs/content/2.guide/2.features/7.error-handling.md index 81a328ca9f..a5d2d575e0 100644 --- a/docs/content/3.docs/1.usage/8.error-handling.md +++ b/docs/content/2.guide/2.features/7.error-handling.md @@ -1,4 +1,4 @@ -# Error handling +# Error Handling ## Handling errors @@ -71,24 +71,33 @@ const handleError = () => clearError({ redirect: '/' }) ## Error helper methods -### useError +### `useError` * `function useError (): Ref` This function will return the global Nuxt error that is being handled. -### throwError +::ReadMore{link="/api/composables/use-error"} +:: + +### `throwError` * `function throwError (err: string | Error): Error` You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page (as above) which you can clear with `clearError`. -### clearError +::ReadMore{link="/api/composables/throw-error"} +:: + +### `clearError` * `function clearError (redirect?: string): Promise` This function will clear the currently handled Nuxt error. It also takes an optional path to redirect to (for example, if you want to navigate to a 'safe' page). +::ReadMore{link="/api/composables/clear-error"} +:: + ## Rendering errors within your app Nuxt also provides a `` component that allows you to handle client-side errors within your app, without replacing your entire site with an error page. @@ -105,9 +114,9 @@ If you navigate to another route, the error will be cleared automatically. ```vue [pages/index.vue]