Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add README for examples vuex-store, async-data and global-css - Add examples/global-css/ - Feature: we can now use nuxt.config.js to add global css files and modules - Fix: show webpack error of compilation
- Loading branch information
Showing
12 changed files
with
140 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
## Loading async data | ||
# Async data with Nuxt.js | ||
|
||
To launch this example | ||
## data(context) | ||
|
||
> Nuxt.js *supercharges* the `data` method from vue.js to let you handle async operation before setting the real component data. | ||
`data` is called every time before loading the component (*only if attached to a route*). It can be called from the server-side or before navigating to the corresponding route. | ||
|
||
The `data` method receives the context as the first argument, you can use it to fetch some data and return the component data. To make the data method asynchronous, **return a Promise**, nuxt.js will wait for the promise to be resolved before rendering the Component. | ||
|
||
For example: | ||
```js | ||
export default { | ||
data ({ params }) { | ||
return axios.get(`http://my-api/posts/${params.id}`) | ||
.then((res) => { | ||
return { title: res.data.title } | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
And then, you can display the data inside your template: | ||
|
||
```html | ||
<template> | ||
<h1>{{ title }}</h1> | ||
</template> | ||
``` | ||
|
||
## Demo | ||
|
||
```bash | ||
npm install # or yarn install | ||
npm install | ||
npm start | ||
``` | ||
|
||
Go to [http://localhost:3000](http://localhost:3000) | ||
Go to [http://localhost:3000](http://localhost:3000) and navigate inside the app. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Global CSS with Nuxt.js | ||
|
||
> Nuxt.js let you define the CSS files/modules/libraries you want to set as globals (included in every pages). | ||
|
||
## Usage | ||
|
||
In `nuxt.config.js` file, add the CSS ressources: | ||
|
||
```js | ||
const { resolve } = require('path') | ||
|
||
module.exports = { | ||
css: [ | ||
// Load a node.js module | ||
'hover.css/css/hover-min.css', | ||
// node.js module but we specify the lang | ||
{ src: 'bulma', lang: 'sass' }, | ||
// Css file in the project | ||
// It is important to give an absolute path | ||
resolve(__dirname, 'css/main.css') | ||
] | ||
} | ||
``` | ||
|
||
## Demo | ||
|
||
To see the demo working: | ||
```bash | ||
npm install | ||
npm start | ||
``` | ||
|
||
Go to [http://localhost:8080](http://localhost:8080) and navigate inside the app. | ||
|
||
## Production | ||
|
||
In production, they will be minified and extracted in a file named `styles.css` and added in the `<head>` of the page. | ||
|
||
To launch the demo in production mode so you can see the ``<head>` populated with the `<link>` tag: | ||
|
||
```bash | ||
NODE_ENV=production npm start | ||
``` | ||
|
||
Go to [http://localhost:8080](http://localhost:8080) and check the source code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
background: #eee; | ||
text-align: center; | ||
padding-top: 30px; | ||
} | ||
.content { | ||
margin-top: 100px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
const { resolve } = require('path') | ||
|
||
module.exports = { | ||
// Nuxt.js configuration file | ||
// Please look at https://nuxtjs.org/docs/config-file | ||
css: [ | ||
'hover.css/css/hover-min.css', | ||
{ src: 'bulma', lang: 'sass' }, | ||
resolve(__dirname, 'css/main.css') | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<template> | ||
<div class="content"> | ||
<h1 class="title">Another Page</h1> | ||
<p><router-link to="/" class="button is-medium is-info hvr-wobble-vertical">Another button</router-link></p> | ||
<p><router-link to="/">Back home</router-link></p> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
<template> | ||
<p>Hello {{ name }}!</p> | ||
<div class="content"> | ||
<h1 class="title">Custom CSS!</h1> | ||
<p><router-link to="/about" class="button is-medium is-primary hvr-float-shadow">I am a button</router-link></p> | ||
<p><router-link to="/about">About page</router-link></p> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data () { | ||
return { name: 'world' } | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
p { | ||
font-size: 20px; | ||
text-align: center; | ||
padding: 100px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters