SlideShare a Scribd company logo
1 of 3
Download to read offline
Need help on your path to Vue Mastery? Check out our tutorials.
This cheat sheet is created by
VueMastery.com
The ultimate learning resource for Vue developers.
STARTING A NEW PROJECT
From Nuxt toolkit:
$ npx create-nuxt-app <project-name>
$ cd <project-name>
$ npm install
$ npm run dev
From scratch:
package.json
{
"name": "my-app",
"scripts": {
"dev": "nuxt"
}
}
$ npm install --save nuxt
$ npm run dev
FOLDER STRUCTURE
ASSETS - Uncompiled assets (like Less / Sass).
STATIC - Unchanging files (like robots.txt).
COMPONENTS
LAYOUTS - Application layouts.
MIDDLEWARE - Custom functions which
run before pages.
PAGES - Application views & routes from
which the router is dynamically generated.
PLUGINS - JS plugins run before Vue.js init.
STORE - Vuex Store files.
PAGES
Nuxt reads the file tree inside the pages directory to create your
application’s routes:
pages
index.vue
users
index.vue
_id.vue
PAGE KEYS
export default {
asyncData (context) {
return
axios.get(`https://my-api/posts/${context.params.id}`)
.then((res) => {
return { title: res.data.title }
})
},
fetch (context) {
return axios.get('http://my-api/stars').then((res)
=> {
context.store.commit('setStars', res.data)
})
},
head () {
return {
title: this.title,
meta: [
{ hid: 'description', name: 'description',
content: 'My custom description' }
]
}
},
layout: 'my-custom-layout',
validate (context) {
return /^d+$/.test(context.params.id)
},
transition: {
name: 'my-custom-transition',
mode: 'out-in'
}
}
Set the HTML Head tags for the current page. Uses vue-meta.
Your component's data is available with this.
Choose a custom layout for your page.
If false, Nuxt loads the error page instead.
Must be a number
Define a custom transition for current page
Installs dependencies
Launches the project
loaded when root path /
_ defines a dynamic route with a param /users/123
/users path
Runs the nuxt script / initiates the app
Installs nuxt and saves it in package.json
NUXT.JS ESSENTIALS
CHEAT SHEET
NUXT COMPONENTS
Use <nuxt-link> to navigate between pages in your
components.
<nuxt-link v-bind:to="'/users' + user.name" >
{{ user.fullName }}'s Profile</nuxt-link>
Use <nuxt-child/> to display child component routes in
your nested routes.
<template>
<div>
<h1>I am the parent view</h1>
<nuxt-child />
</div>
</template>
LAYOUTS
Put application layouts in the layouts folder. Use
the nuxt component to display content.
layouts/my-custom-layout.vue
<template>
<div class="container">
<nuxt />
</div>
</template>
ERROR PAGES
Customize the error page with layouts/error.vue. Do not
include <nuxt/> inside its template.
<template>
<h1 v-if="error.statusCode === 404">
Page not found
</h1>
<h1 v-else>An error occurred</h1>
<nuxt-link to="/">Home page</nuxt-link>
</template>
<script>
export default {
props: ['error'],
layout: 'my-error-layout'
}
</script>
ALIASES FOR REFERENCING FILES
~ to reference the source directory
<template>
<img src="~/assets/your_image.png"/>
</template>
<script>
import Visits from '~/components/Visits'
export default {
components: { Visits }
}
</script>
VUEX STORE
Nuxt automatically adds Vuex to your project if you have an
index.js file in your store folder. This file must export a
method which returns a Vuex instance.
You can now use this.$store inside of your components.
<template>
<button @click="$store.commit('increment')">
{{ $store.state.counter }}
</button>
</template>
You can set a custom layout for the error page
VueMastery.com
ADDITIONAL VUE LEARNING
Dive deep into advanced Vue concepts in our
Advanced Components course.
• Learn the full functionality of Vue
• Understand how Vue internals work together
• Discover how to extend Vue as needed
Plus 5 bonus videos exploring the Vue source code
with Evan You, the creator of Vue.
NUXT.JS ESSENTIALS
CHEAT SHEET
Need help on your path to Vue Mastery? Check out our tutorials on VueMastery.com
NUXT.CONFIG.JS
For configuring your application
export default {
css: [
'bulma/css/bulma.css',
'~/css/main.css'
],
generate: {
routes: function () {
return [
'/users/1',
'/users/2',
'/users/3'
];
}
},
loading: '~/components/loading.vue',
head: {
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content:
'width=device-width, initial-scale=1' }
],
link: [{
rel: 'stylesheet',
href: 'https://font.com',
}]
},
transition: {
name: 'page’,
mode: 'out-in'
},
plugins: ['~/plugins/vue-notifications']
}
DEPLOYMENT METHODS
1. SPA (SINGLE PAGE APPLICATION)
Benefit: Organize your project using convention over
configuration folder structure and config files. Easy
development server.
∙ Change mode in nuxt.config.js to spa.
• Run npm run build
• Deploy the created dist/ folder to your static hosting
like GitHub Pages for example.
2. STATIC
Benefit: All pages get pre-rendered into HTML and have a
high SEO and page load score. The content is generated at
build time.
• Run npm run generate
• Deploy the created dist/ folder with all the generated
HTML files and folders to your static hosting.
3. UNIVERSAL
Benefit: Execute your JavaScript on both the client and the
server. All routes have high SEO and page load score.
Dynamically get routes rendered on the server before
being sent to client.
• Upload the contents of your application to your
server of choice.
• Run nuxt build to build your application.
• Run nuxt start to start your application and start
accepting requests.
RUNNING AND BUILDING
$ nuxt
$ nuxt generate
$ nuxt build
$ nuxt start
Build the application and generate every route as a HTML file
To add global CSS files
To generate static pages from
dynamic routes, specify them here
Set a custom loading component
Set HTML Head tags for every page
Set the default transition for all pages
Launch a development server on Localhost:3000 with hot-reloading
Build your application for production with webpack and minify assets
Start the server in production mode
Nuxt.js is an open source project supported by the
community. To sponsor the project, head over to
Open Collective: opencollective.com/nuxtjs
NUXT.JS ESSENTIALS
CHEAT SHEET

More Related Content

What's hot (20)

Express js
Express jsExpress js
Express js
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
A la découverte de vue.js
A la découverte de vue.jsA la découverte de vue.js
A la découverte de vue.js
 
Ionic, AngularJS,Cordova,NodeJS,Sass
Ionic, AngularJS,Cordova,NodeJS,SassIonic, AngularJS,Cordova,NodeJS,Sass
Ionic, AngularJS,Cordova,NodeJS,Sass
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
 
Vue.js
Vue.jsVue.js
Vue.js
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Express node js
Express node jsExpress node js
Express node js
 
Scala API - Azure Event Hub Integration
Scala API - Azure Event Hub IntegrationScala API - Azure Event Hub Integration
Scala API - Azure Event Hub Integration
 
Angular
AngularAngular
Angular
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IO
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Support cours angular
Support cours angularSupport cours angular
Support cours angular
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014
 

Similar to Nuxtjs cheat-sheet

How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4Vijay Shukla
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalystsvilen.ivanov
 
WEBPACK
WEBPACKWEBPACK
WEBPACKhome
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applicationsAstrails
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.jsPagepro
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptKaty Slemon
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdevFrank Rousseau
 
Server Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsServer Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsJessie Barnett
 
Creating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactCreating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactAngela Kristine Juvet Branaes
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerKaty Slemon
 
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented DesignCSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented DesignKate Travers
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 

Similar to Nuxtjs cheat-sheet (20)

How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
nuxt-en.pdf
nuxt-en.pdfnuxt-en.pdf
nuxt-en.pdf
 
vitepress-en.pdf
vitepress-en.pdfvitepress-en.pdf
vitepress-en.pdf
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
 
WEBPACK
WEBPACKWEBPACK
WEBPACK
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
Server Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsServer Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.js
 
code-camp-meteor
code-camp-meteorcode-camp-meteor
code-camp-meteor
 
Creating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactCreating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and react
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
 
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented DesignCSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
 
Meteor Day Talk
Meteor Day TalkMeteor Day Talk
Meteor Day Talk
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Nuxt Talk
Nuxt TalkNuxt Talk
Nuxt Talk
 
Death of a Themer
Death of a ThemerDeath of a Themer
Death of a Themer
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Nuxtjs cheat-sheet

  • 1. Need help on your path to Vue Mastery? Check out our tutorials. This cheat sheet is created by VueMastery.com The ultimate learning resource for Vue developers. STARTING A NEW PROJECT From Nuxt toolkit: $ npx create-nuxt-app <project-name> $ cd <project-name> $ npm install $ npm run dev From scratch: package.json { "name": "my-app", "scripts": { "dev": "nuxt" } } $ npm install --save nuxt $ npm run dev FOLDER STRUCTURE ASSETS - Uncompiled assets (like Less / Sass). STATIC - Unchanging files (like robots.txt). COMPONENTS LAYOUTS - Application layouts. MIDDLEWARE - Custom functions which run before pages. PAGES - Application views & routes from which the router is dynamically generated. PLUGINS - JS plugins run before Vue.js init. STORE - Vuex Store files. PAGES Nuxt reads the file tree inside the pages directory to create your application’s routes: pages index.vue users index.vue _id.vue PAGE KEYS export default { asyncData (context) { return axios.get(`https://my-api/posts/${context.params.id}`) .then((res) => { return { title: res.data.title } }) }, fetch (context) { return axios.get('http://my-api/stars').then((res) => { context.store.commit('setStars', res.data) }) }, head () { return { title: this.title, meta: [ { hid: 'description', name: 'description', content: 'My custom description' } ] } }, layout: 'my-custom-layout', validate (context) { return /^d+$/.test(context.params.id) }, transition: { name: 'my-custom-transition', mode: 'out-in' } } Set the HTML Head tags for the current page. Uses vue-meta. Your component's data is available with this. Choose a custom layout for your page. If false, Nuxt loads the error page instead. Must be a number Define a custom transition for current page Installs dependencies Launches the project loaded when root path / _ defines a dynamic route with a param /users/123 /users path Runs the nuxt script / initiates the app Installs nuxt and saves it in package.json NUXT.JS ESSENTIALS CHEAT SHEET
  • 2. NUXT COMPONENTS Use <nuxt-link> to navigate between pages in your components. <nuxt-link v-bind:to="'/users' + user.name" > {{ user.fullName }}'s Profile</nuxt-link> Use <nuxt-child/> to display child component routes in your nested routes. <template> <div> <h1>I am the parent view</h1> <nuxt-child /> </div> </template> LAYOUTS Put application layouts in the layouts folder. Use the nuxt component to display content. layouts/my-custom-layout.vue <template> <div class="container"> <nuxt /> </div> </template> ERROR PAGES Customize the error page with layouts/error.vue. Do not include <nuxt/> inside its template. <template> <h1 v-if="error.statusCode === 404"> Page not found </h1> <h1 v-else>An error occurred</h1> <nuxt-link to="/">Home page</nuxt-link> </template> <script> export default { props: ['error'], layout: 'my-error-layout' } </script> ALIASES FOR REFERENCING FILES ~ to reference the source directory <template> <img src="~/assets/your_image.png"/> </template> <script> import Visits from '~/components/Visits' export default { components: { Visits } } </script> VUEX STORE Nuxt automatically adds Vuex to your project if you have an index.js file in your store folder. This file must export a method which returns a Vuex instance. You can now use this.$store inside of your components. <template> <button @click="$store.commit('increment')"> {{ $store.state.counter }} </button> </template> You can set a custom layout for the error page VueMastery.com ADDITIONAL VUE LEARNING Dive deep into advanced Vue concepts in our Advanced Components course. • Learn the full functionality of Vue • Understand how Vue internals work together • Discover how to extend Vue as needed Plus 5 bonus videos exploring the Vue source code with Evan You, the creator of Vue. NUXT.JS ESSENTIALS CHEAT SHEET
  • 3. Need help on your path to Vue Mastery? Check out our tutorials on VueMastery.com NUXT.CONFIG.JS For configuring your application export default { css: [ 'bulma/css/bulma.css', '~/css/main.css' ], generate: { routes: function () { return [ '/users/1', '/users/2', '/users/3' ]; } }, loading: '~/components/loading.vue', head: { meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' } ], link: [{ rel: 'stylesheet', href: 'https://font.com', }] }, transition: { name: 'page’, mode: 'out-in' }, plugins: ['~/plugins/vue-notifications'] } DEPLOYMENT METHODS 1. SPA (SINGLE PAGE APPLICATION) Benefit: Organize your project using convention over configuration folder structure and config files. Easy development server. ∙ Change mode in nuxt.config.js to spa. • Run npm run build • Deploy the created dist/ folder to your static hosting like GitHub Pages for example. 2. STATIC Benefit: All pages get pre-rendered into HTML and have a high SEO and page load score. The content is generated at build time. • Run npm run generate • Deploy the created dist/ folder with all the generated HTML files and folders to your static hosting. 3. UNIVERSAL Benefit: Execute your JavaScript on both the client and the server. All routes have high SEO and page load score. Dynamically get routes rendered on the server before being sent to client. • Upload the contents of your application to your server of choice. • Run nuxt build to build your application. • Run nuxt start to start your application and start accepting requests. RUNNING AND BUILDING $ nuxt $ nuxt generate $ nuxt build $ nuxt start Build the application and generate every route as a HTML file To add global CSS files To generate static pages from dynamic routes, specify them here Set a custom loading component Set HTML Head tags for every page Set the default transition for all pages Launch a development server on Localhost:3000 with hot-reloading Build your application for production with webpack and minify assets Start the server in production mode Nuxt.js is an open source project supported by the community. To sponsor the project, head over to Open Collective: opencollective.com/nuxtjs NUXT.JS ESSENTIALS CHEAT SHEET