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

What's hot (20)

Introduction à React
Introduction à ReactIntroduction à React
Introduction à React
 
React
React React
React
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
Universal React apps in Next.js
Universal React apps in Next.jsUniversal React apps in Next.js
Universal React apps in Next.js
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
Server Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsServer Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.js
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
reactJS
reactJSreactJS
reactJS
 
ReactJs
ReactJsReactJs
ReactJs
 
What is front-end development ?
What is front-end development ?What is front-end development ?
What is front-end development ?
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Top frontend web development tools
Top frontend web development toolsTop frontend web development tools
Top frontend web development tools
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]
 
Basics of VueJS
Basics of VueJSBasics of VueJS
Basics of VueJS
 

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
 
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
 
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
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 

Recently uploaded

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

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