SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
A minimalist framework
for server-rendered Vue.js applications
Inspired by Next.js
Built on top of Vue.js 2
Server-side Rendering
With Node.js
ES6 Transpilation
With Babel
Code Splitting
With Webpack
Focus on writing
*.vue files
Example
npm install --save nuxt
package.json
{
“dependencies": {
“nuxt”: "latest"
},
“scripts”: {
“dev”: “nuxt"
}
}
pages/index.vue
<template>
<h1>Hello {{ name }}</h1>
</template>
<script>
export default {
data () {
return { name: ‘world’ }
}
}
</script>
npm run dev
http://localhost:3000
<h1>Hello world</h1>
pages/ is the main API
pages/index.vue —> /
pages/about.vue —> /about
Async Data
pages/index.vue
<template>
<ul>
<li v-for=“post in posts”>
{{ post.title }}
</li>
</ul>
</template>
<script>
import axios from 'axios'
export default {
data () {
return axios.get(‘https://my-api')
.then((res) => {
return { posts: res.data }
})
}
}
</script>
Server Data
pages/index.vue
<template>
<h1>Hi from {{ name }}</h1>
</template>
<script>
export default {
data ({ req }) {
return {
name: (req ? ‘server' : ‘client' }
}
}
}
</script>
data(context)
- isServer
- isClient
- isDev
- req
- res
- params
- query
- env
- route
- base
- store
- error({ statusCode, message })
- redirect([status], path, [query])
pages/auth.vue
<template>
<h1>Authenticated</h1>
</template>
<script>
export default {
data ({ store, redirect }) {
if (store.user.authUser)
return redirect(‘/login’)
return {}
}
}
</script>
Customisable
nuxt.config.js
Custom Routes
Ex: pages/users/_id.vue -> /users/:id
Vue plugins
Ex: vuelidate, vue-i18n, etc.
nuxt.config.js
module.exports = {
plugins: [
‘plugins/vuelidate.js’
],
build: {
vendor: [‘vuelidate’]
}
}
plugins/vuelidate.js
import Vue from 'vue'
import Validation from 'vuelidate'
Vue.use(Validation)
Head elements
title, meta tags, etc.
nuxt.config.js
module.exports = {
head: {
title: ‘Default title’,
meta: [
{ charset: ‘utf-8’ }
]
}
}
pages/index.vue
<template>
<h1>Hello world</h1>
</template>
<script>
export default {
head: {
title: ‘Index page'
}
}
</script>
Vuex Store
With store/index.js
router/index.js
import Vuex from 'vuex'
const store = new Vuex.Store({
state: {
counter: 0
},
mutations: {
increment (state) {
state.counter++
}
}
})
export default store
pages/index.vue
<template>
<button @click=“$store.commit(‘increment’)">
{{ $store.state.counter }}
</button>
</template>
Layouts
layouts/app.vue
layouts/app.vue
<template>
<nuxt-container>
<p>My nav bar here!</p>
<nuxt></nuxt>
</nuxt-container>
</template>
<style src=“~assets/main.css”></style>
Etc.
- Routes Transitions
- Static files
- Error page
- Testing
- Environment variables
- postcss plugins
- babel configuration
- webpack config
Use it
Programmatically
server.js
const Nuxt = require(‘nuxt')
const nuxt = new Nuxt(options)
nuxt.build()
.then(() => {
// nuxt.renderRoute(‘/‘)
})
Express Middleware
app.use(nuxt.render)
server.js
const Nuxt = require(‘nuxt’)
const app = require(‘express’)()
new Nuxt(options)
.then((nuxt) => {
app.use(nuxt.render)
app.listen(3000)
})
Server Deployment
package.json
{
“dependencies": {
“nuxt”: "latest"
},
“scripts”: {
“dev”: “nuxt”,
“build”: “nuxt build”,
“start”: “nuxt start"
}
}
Serverless Deployment
nuxt generate
pages/index.vue —> /index.html
pages/about.vue —> /about/index.html
nuxtjs.org
Chopin brothers
Made with nuxt.js

Contenu connexe

Tendances (20)

Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to 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
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
An Introduction to Vuejs
An Introduction to VuejsAn Introduction to Vuejs
An Introduction to Vuejs
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Basics of Vue.js 2019
Basics of Vue.js 2019Basics of Vue.js 2019
Basics of Vue.js 2019
 
Nuxtjs cheat-sheet
Nuxtjs cheat-sheetNuxtjs cheat-sheet
Nuxtjs cheat-sheet
 
Next.js Introduction
Next.js IntroductionNext.js Introduction
Next.js Introduction
 
State manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to VuexState manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to Vuex
 
Vue Vuex 101
Vue Vuex 101Vue Vuex 101
Vue Vuex 101
 
Vue JS Intro
Vue JS IntroVue JS Intro
Vue JS Intro
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 

En vedette

2013 053. Retour des PTG à plateaux fixes. Pourquoi ?
2013 053. Retour des PTG à plateaux fixes. Pourquoi ?2013 053. Retour des PTG à plateaux fixes. Pourquoi ?
2013 053. Retour des PTG à plateaux fixes. Pourquoi ?jofdf
 
5 Little Things that Can Make a Big Difference in Your Photos
5 Little Things that Can Make a Big Difference in Your Photos5 Little Things that Can Make a Big Difference in Your Photos
5 Little Things that Can Make a Big Difference in Your PhotosCreative Market
 
10 PowerPoint Templates That Don't Suck
10 PowerPoint Templates That Don't Suck10 PowerPoint Templates That Don't Suck
10 PowerPoint Templates That Don't SuckPresentation Panda
 

En vedette (6)

2013 053. Retour des PTG à plateaux fixes. Pourquoi ?
2013 053. Retour des PTG à plateaux fixes. Pourquoi ?2013 053. Retour des PTG à plateaux fixes. Pourquoi ?
2013 053. Retour des PTG à plateaux fixes. Pourquoi ?
 
University of Dammam-Inspiring a new generation of learners
University of Dammam-Inspiring a new generation of learnersUniversity of Dammam-Inspiring a new generation of learners
University of Dammam-Inspiring a new generation of learners
 
5 Little Things that Can Make a Big Difference in Your Photos
5 Little Things that Can Make a Big Difference in Your Photos5 Little Things that Can Make a Big Difference in Your Photos
5 Little Things that Can Make a Big Difference in Your Photos
 
10 PowerPoint Templates That Don't Suck
10 PowerPoint Templates That Don't Suck10 PowerPoint Templates That Don't Suck
10 PowerPoint Templates That Don't Suck
 
Vue.js with Go
Vue.js with GoVue.js with Go
Vue.js with Go
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
 

Similaire à Nuxt.js - Introduction

Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLaurence Svekis ✔
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
Node.js in action
Node.js in actionNode.js in action
Node.js in actionSimon Su
 
Fullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endFullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endEzequiel Maraschio
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Warsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - WebpackWarsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - WebpackRadosław Rosłaniec
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applicationsAstrails
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalystsvilen.ivanov
 
Nodejs quick start
Nodejs quick startNodejs quick start
Nodejs quick startGuangyao Cao
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development toolsSimon Kim
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstackRoberto Polli
 
Pluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with DockerPluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with DockerElton Stoneman
 

Similaire à Nuxt.js - Introduction (20)

Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
NestJS
NestJSNestJS
NestJS
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
Fullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endFullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-end
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
ASP.NET vNext
ASP.NET vNextASP.NET vNext
ASP.NET vNext
 
Warsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - WebpackWarsaw Frontend Meetup #1 - Webpack
Warsaw Frontend Meetup #1 - Webpack
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
GradleFX
GradleFXGradleFX
GradleFX
 
Nodejs quick start
Nodejs quick startNodejs quick start
Nodejs quick start
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development tools
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstack
 
Asp.net
Asp.netAsp.net
Asp.net
 
Pluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with DockerPluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with Docker
 

Nuxt.js - Introduction