|
1 | 1 | ---
|
2 | 2 | title: Views
|
3 |
| -description: The Views section describes all you need to configure data and views for a specific route in your Nuxt.js application. (Pages, layouts and HTML Head) |
| 3 | +description: The Views section describes all you need to configure data and views for a specific route in your Nuxt.js application. (Document, Layouts, Pages and HTML Head) |
4 | 4 | ---
|
5 | 5 |
|
6 |
| -> The Views section describes all you need to configure data and views for a specific route in your Nuxt.js application. (Pages, layouts and HTML Head) |
| 6 | +> The Views section describes all you need to configure data and views for a specific route in your Nuxt.js application. (Document, Layouts, Pages and HTML Head) |
7 | 7 |
|
8 |
| -## Pages |
| 8 | + |
9 | 9 |
|
10 |
| -Every Page component is a Vue component, but Nuxt.js adds special keys to make the development of your universal application the easiest way possible. |
| 10 | +## Document |
11 | 11 |
|
12 |
| -```html |
13 |
| -<template> |
14 |
| - <h1 class="red">Hello {{ name }}!</h1> |
15 |
| -</template> |
| 12 | +> You can customise the main document with nuxt.js |
16 | 13 |
|
17 |
| -<script> |
18 |
| -export default { |
19 |
| - data (context) { |
20 |
| - // called every time before loading the component |
21 |
| - return { name: 'World' } |
22 |
| - }, |
23 |
| - fetch () { |
24 |
| - // The fetch method is used to fill the store before rendering the page |
25 |
| - }, |
26 |
| - head () { |
27 |
| - // Set Meta Tags for this Page |
28 |
| - }, |
29 |
| - // and more functionality to discover |
30 |
| - ... |
31 |
| -} |
32 |
| -</script> |
| 14 | +To extend the html template, create a `app.html` at the root of your project. |
33 | 15 |
|
34 |
| -<style> |
35 |
| -.red { |
36 |
| - color: red; |
37 |
| -} |
38 |
| -</style> |
39 |
| -``` |
| 16 | +The default template is: |
40 | 17 |
|
| 18 | +```html |
| 19 | +<!DOCTYPE html> |
| 20 | +<html {{ HTML_ATTRS }}> |
| 21 | + <head> |
| 22 | + {{ HEAD }} |
| 23 | + </head> |
| 24 | + <body {{ BODY_ATTRS }}> |
| 25 | + {{ APP }} |
| 26 | + </body> |
| 27 | +</html> |
| 28 | +``` |
41 | 29 |
|
42 |
| -| Attribute | Description | |
43 |
| -|-----------|-------------| |
44 |
| -| data | The most important key, it has the same purpose as [Vue data](https://vuejs.org/v2/api/#Options-Data) but it can be asynchronous and receives the context as argument, please read the [async data documentation](/guide/async-data) to learn how it works. | |
45 |
| -| fetch | Used to fill the store before rendering the page, it's like the data method except it doesn't set the component data. See the [API Pages fetch documentation](/api/pages-fetch). | |
46 |
| -| head | Set specific Meta Tags for the current page, see [API Pages head documentation](/api/pages-head). | |
47 |
| -| layout | Specify a layout defined in the `layouts` directory, see [API Pages layouts documentation](/api/pages-layout). | |
48 |
| -| transition | Set a specific transition for the page, see [API Pages transition](/api/pages-transition). | |
49 |
| -| scrollToTop | Boolean, by default: `false`. Specify if you want the page to scroll to the top before rendering the page, it's used for [nested routes](/guide/routing#nested-routes). | |
50 |
| -| validate | Validator function for a [dynamic route](/guide/routing#dynamic-routes). | |
51 |
| -| middleware | Set a middleware for this page, the middleware will be called before rendering the page, see [routes middleware](/guide/routing#middleware). | |
| 30 | +One example if to add conditional CSS classes for IE: |
52 | 31 |
|
53 |
| -More information about the pages properties usage: [API Pages](/api) |
| 32 | +```html |
| 33 | +<!DOCTYPE html> |
| 34 | +<!--[if IE 9]><html lang="en-US" class="lt-ie9 ie9" {{ HTML_ATTRS }}><![endif]--> |
| 35 | +<!--[if (gt IE 9)|!(IE)]><!--><html {{ HTML_ATTRS }}><!--<![endif]--> |
| 36 | + <head> |
| 37 | + {{ HEAD }} |
| 38 | + </head> |
| 39 | + <body {{ BODY_ATTRS }}> |
| 40 | + {{ APP }} |
| 41 | + </body> |
| 42 | +</html> |
| 43 | +``` |
54 | 44 |
|
55 | 45 | ## Layouts
|
56 | 46 |
|
@@ -123,6 +113,53 @@ More information about the layout property: [API Pages layout](/api/pages-layout
|
123 | 113 |
|
124 | 114 | Check the [demonstration video](https://www.youtube.com/watch?v=YOKnSTp7d38) to see it in action.
|
125 | 115 |
|
| 116 | +## Pages |
| 117 | + |
| 118 | +Every Page component is a Vue component, but Nuxt.js adds special keys to make the development of your universal application the easiest way possible. |
| 119 | + |
| 120 | +```html |
| 121 | +<template> |
| 122 | + <h1 class="red">Hello {{ name }}!</h1> |
| 123 | +</template> |
| 124 | + |
| 125 | +<script> |
| 126 | +export default { |
| 127 | + asyncData (context) { |
| 128 | + // called every time before loading the component |
| 129 | + return { name: 'World' } |
| 130 | + }, |
| 131 | + fetch () { |
| 132 | + // The fetch method is used to fill the store before rendering the page |
| 133 | + }, |
| 134 | + head () { |
| 135 | + // Set Meta Tags for this Page |
| 136 | + }, |
| 137 | + // and more functionality to discover |
| 138 | + ... |
| 139 | +} |
| 140 | +</script> |
| 141 | + |
| 142 | +<style> |
| 143 | +.red { |
| 144 | + color: red; |
| 145 | +} |
| 146 | +</style> |
| 147 | +``` |
| 148 | + |
| 149 | + |
| 150 | +| Attribute | Description | |
| 151 | +|-----------|-------------| |
| 152 | +| asyncData | The most important key, it can be asynchronous and receives the context as argument, please read the [async data documentation](/guide/async-data) to learn how it works. | |
| 153 | +| fetch | Used to fill the store before rendering the page, it's like the data method except it doesn't set the component data. See the [API Pages fetch documentation](/api/pages-fetch). | |
| 154 | +| head | Set specific Meta Tags for the current page, see [API Pages head documentation](/api/pages-head). | |
| 155 | +| layout | Specify a layout defined in the `layouts` directory, see [API Pages layouts documentation](/api/pages-layout). | |
| 156 | +| transition | Set a specific transition for the page, see [API Pages transition](/api/pages-transition). | |
| 157 | +| scrollToTop | Boolean, by default: `false`. Specify if you want the page to scroll to the top before rendering the page, it's used for [nested routes](/guide/routing#nested-routes). | |
| 158 | +| validate | Validator function for a [dynamic route](/guide/routing#dynamic-routes). | |
| 159 | +| middleware | Set a middleware for this page, the middleware will be called before rendering the page, see [routes middleware](/guide/routing#middleware). | |
| 160 | + |
| 161 | +More information about the pages properties usage: [API Pages](/api) |
| 162 | + |
126 | 163 | ## HTML Head
|
127 | 164 |
|
128 | 165 | Nuxt.js uses [vue-meta](https://github.com/declandewet/vue-meta) to update the `headers` and `html attributes` of your application.
|
@@ -163,38 +200,3 @@ More information about the head method: [API Configuration head](/api/configurat
|
163 | 200 | More information about the head method: [API Pages head](/api/pages-head)
|
164 | 201 |
|
165 | 202 | <p class="Alert">To avoid any duplication when used in child component, please give a unique identifier with the `hid` key, please [read more about it](https://github.com/declandewet/vue-meta#lists-of-tags).</p>
|
166 |
| - |
167 |
| -## Document |
168 |
| - |
169 |
| -> You can customise the main document with nuxt.js |
170 |
| -
|
171 |
| -To extend the html template, create a `app.html` at the root of your project. |
172 |
| - |
173 |
| -The default template is: |
174 |
| - |
175 |
| -```html |
176 |
| -<!DOCTYPE html> |
177 |
| -<html {{ HTML_ATTRS }}> |
178 |
| - <head> |
179 |
| - {{ HEAD }} |
180 |
| - </head> |
181 |
| - <body {{ BODY_ATTRS }}> |
182 |
| - {{ APP }} |
183 |
| - </body> |
184 |
| -</html> |
185 |
| -``` |
186 |
| - |
187 |
| -One example if to add conditional CSS classes for IE: |
188 |
| - |
189 |
| -```html |
190 |
| -<!DOCTYPE html> |
191 |
| -<!--[if IE 9]><html lang="en-US" class="lt-ie9 ie9" {{ HTML_ATTRS }}><![endif]--> |
192 |
| -<!--[if (gt IE 9)|!(IE)]><!--><html {{ HTML_ATTRS }}><!--<![endif]--> |
193 |
| - <head> |
194 |
| - {{ HEAD }} |
195 |
| - </head> |
196 |
| - <body {{ BODY_ATTRS }}> |
197 |
| - {{ APP }} |
198 |
| - </body> |
199 |
| -</html> |
200 |
| -``` |
|
0 commit comments