SlideShare une entreprise Scribd logo
1  sur  77
SEBASTIEN CHOPIN
Github & Twitter: Atinux
Working @ Neo.9
Paris
A 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
Automatic Code Splitting
Every routes and layouts
Hot Reloading
With Webpack + Vue-Loader
Focus on writing
*.vue files
USAGE
npm install --save nuxt
npm run dev
DEMO
ROUTING
pages/ is the main API
pages/index.vue —> /
Simple Routes
pages/about.vue —> /about
pages/_.vue —> /*
pages/users/_id.vue —> /users/:id
Dynamic Routes
Nested Routes
pages/users/_id.vue —> Parent View
pages/users/_id/index.vue —> Child View
pages/users/_id/feed.vue —> Child View
<nuxt-link>
<nuxt-link>About page</nuxt-link>
<nuxt-link to=“/about”>About page</nuxt-link>
Same as router-link
DEMO
ASYNC DATA
DEMO
CONTEXT
asyncData(context)
Key Type Where Description
isClient Boolean Client & Server true on client-side
isServer Boolean Client & Server true on server-side
isDev Boolean Client & Server true on development
env Object Client & Server Object defined in nuxt.config.js
asyncData(context)
Key Type Where Description
route
Route Instance
(vue-router)
Client & Server Route object given by vue-router
params Object Client & Server Alias of route.params
query Object Client & Server Alias of route.query
store
Store Instance
(vuex)
Client & Server
Vuex store instance
(only when store activated)
asyncData(context)
Key Type Where Description
req http.Request Server Request from the node.js server.
res http.Response Server Response from the node.js server.
redirect Function Client & Server redirect([statusCode,] path [, query])
error Function Client & Server error({ statusCode, message })
LAYOUTS
Add a layouts/ directory
layouts/default.vue
layouts/dark.vue
pages/index.vue
DEMO
STORE
With Vuex
Add a store/ directory
store/index.js pages/index.vue
pages/about.vue
pages/index.vuestore/index.js
pages/about.vue
DEMO
(async) nuxtServerInit action
MIDDLEWARE
Add a middleware/ directory
middleware/auth.js
pages/secret.vue
DEMO
CONFIGURATION
Via nuxt.config.js
HEAD ELEMENTS
With vue-meta
USE IT
PROGRAMMATICALLY
Express middleware
app.use(nuxt.render)
SERVER DEPLOYMENT
With now.sh
now
That’s it.
STATIC GENERATION
nuxt generate
pages/index.vue —> /dist/index.html
nuxt generate
pages/about.vue —> /dist/about/index.html
now dist/
That’s it.
Github: nuxt/nuxt.js
Version: 0.10.6
30+ contributors
100% coverage
500+ issues closed
30+ examples
3,8K+ stars in 6 months
Coming soon:
nuxtjs.org
5 Languages
Made with nuxt.js
200K+ page views / month
CO-AUTHOR
ALEXANDRE CHOPIN
Github: alexchopin
Versatile Web Application
NEXT
ssr: false
nuxt.config.js layout page
MORE OPEN SOURCE
https://orion.sh
THANK YOU

Contenu connexe

Tendances

Tendances (20)

Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
Webpack
WebpackWebpack
Webpack
 
Webpack
Webpack Webpack
Webpack
 
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
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
Sails.js Intro
Sails.js IntroSails.js Intro
Sails.js Intro
 
Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Single Page Apps with Drupal 8
Single Page Apps with Drupal 8
 
Webpack DevTalk
Webpack DevTalkWebpack DevTalk
Webpack DevTalk
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Webpack slides
Webpack slidesWebpack slides
Webpack slides
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 
A New Vue for Web Development
A New Vue for Web DevelopmentA New Vue for Web Development
A New Vue for Web Development
 
ZK framework
ZK frameworkZK framework
ZK framework
 
Angular2 ecosystem
Angular2 ecosystemAngular2 ecosystem
Angular2 ecosystem
 
Bower power
Bower powerBower power
Bower power
 
Webpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSWebpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JS
 
Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularization
 
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
 
006. React - Redux framework
006. React - Redux framework006. React - Redux framework
006. React - Redux framework
 
Webpack
Webpack Webpack
Webpack
 

Similaire à Server-rendered Vue.js Apps with Nuxt.js Framework

Building the Front End with AngularJS
Building the Front End with AngularJSBuilding the Front End with AngularJS
Building the Front End with AngularJSJohn Ennew
 
Vuejs for Angular developers
Vuejs for Angular developersVuejs for Angular developers
Vuejs for Angular developersMikhail Kuznetcov
 
"Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R...
"Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R..."Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R...
"Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R...Fwdays
 
What is Vuejs.pptx
What is Vuejs.pptxWhat is Vuejs.pptx
What is Vuejs.pptxNhnHVn2
 
Server Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsServer Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsJessie Barnett
 
Extending Kubectl.pptx
Extending Kubectl.pptxExtending Kubectl.pptx
Extending Kubectl.pptxLibbySchulze
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppEdureka!
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.jsVioletta Villani
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.jsCommit University
 
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
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkEdureka!
 
Provisioning, deploying and debugging node.js applications on azure
Provisioning, deploying and debugging node.js applications on azureProvisioning, deploying and debugging node.js applications on azure
Provisioning, deploying and debugging node.js applications on azurePatriek van Dorp
 
ContainerDayVietnam2016: Docker for JS Developer
ContainerDayVietnam2016: Docker for JS DeveloperContainerDayVietnam2016: Docker for JS Developer
ContainerDayVietnam2016: Docker for JS DeveloperDocker-Hanoi
 
Azure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstartAzure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstartDavide Mauri
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.jsPagepro
 
Building websites with Node.ACS
Building websites with Node.ACSBuilding websites with Node.ACS
Building websites with Node.ACSralcocer
 

Similaire à Server-rendered Vue.js Apps with Nuxt.js Framework (20)

Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
Nuxtjs cheat-sheet
Nuxtjs cheat-sheetNuxtjs cheat-sheet
Nuxtjs cheat-sheet
 
Building the Front End with AngularJS
Building the Front End with AngularJSBuilding the Front End with AngularJS
Building the Front End with AngularJS
 
Vuejs for Angular developers
Vuejs for Angular developersVuejs for Angular developers
Vuejs for Angular developers
 
"Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R...
"Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R..."Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R...
"Hidden difficulties of debugger implementation for .NET WASM apps", Andrii R...
 
What is Vuejs.pptx
What is Vuejs.pptxWhat is Vuejs.pptx
What is Vuejs.pptx
 
Server Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.jsServer Side Rendering with Nuxt.js
Server Side Rendering with Nuxt.js
 
Browserify
BrowserifyBrowserify
Browserify
 
Extending Kubectl.pptx
Extending Kubectl.pptxExtending Kubectl.pptx
Extending Kubectl.pptx
 
Meet VueJs
Meet VueJsMeet VueJs
Meet VueJs
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with vue.js
 
Level up apps and websites with vue.js
Level up  apps and websites with vue.jsLevel up  apps and websites with vue.js
Level up apps and websites with 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
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
 
Provisioning, deploying and debugging node.js applications on azure
Provisioning, deploying and debugging node.js applications on azureProvisioning, deploying and debugging node.js applications on azure
Provisioning, deploying and debugging node.js applications on azure
 
ContainerDayVietnam2016: Docker for JS Developer
ContainerDayVietnam2016: Docker for JS DeveloperContainerDayVietnam2016: Docker for JS Developer
ContainerDayVietnam2016: Docker for JS Developer
 
Azure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstartAzure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstart
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Building websites with Node.ACS
Building websites with Node.ACSBuilding websites with Node.ACS
Building websites with Node.ACS
 

Dernier

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
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
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Dernier (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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
 
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
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Server-rendered Vue.js Apps with Nuxt.js Framework

Notes de l'éditeur

  1. Hello everyone. [CLICK] My name is Sebastien, I am French, sorry for my accent 😄, I am currently working at Neo 9 in Paris.
  2. Today I am going to talk about Nuxt.js, first, what is Nuxt.js?
  3. Nuxt.js is an open-source project and it's a framework for server-rendered Vue.js applications. [CLICK] It’s inspired by Next.js
  4. It is built on top of Vue.js 2.1 and the latest version of Vue-router
  5. One of it’s main feature is to allow your application to be server rendered without any extra setup.
  6. You can write ES6 in your code. [CLICK] Nuxt.js uses Babel to transpile your code and make it work for most of the platforms.
  7. Nuxt.js uses Webpack to split your application into multiple file. When the browser load your application, only the strict minimum of JavaScript and CSS will be sent back. [CLICK] You don’t have to do anything, it’s automatic for every routes and layouts.
  8. Nuxt.js also provides hot reloading [CLICK] thanks to Webpack and Vue Loader to improves your development experience.
  9. The only thing you have to do is to focus on writing VUE files.
  10. Let’s see a quick how to use Nuxt.js
  11. First, we need to install nuxt as a dependency of our application with npm
  12. We can add a “dev" script in our package.json to launch nuxt.js.
  13. And then we can create our first page. Here we have a template displaying the name property of our page data, and we set the name to world.
  14. I can now launch Nuxt with npm run dev
  15. Nuxt will generate the routes, bundle your files and run a server on localhost.
  16. If we visit this url in the browser, we can see our index.vue page server-rendered.
  17. Let’s see how it looks like in live.
  18. Let’s see how the routing works in Nuxt
  19. Nuxt.js will match every vue file in our pages directory to a route in our server
  20. [CLICK] So for our index.vue page, it will be the slash route, [CLICK] and for about.vue, the /about route
  21. We can also create dynamic routes, just prefix your route by an underscore to become a dynamic route. [CLICK] The name of file will become a parameter of the route. [CLICK] If you create a page with only an underscore, it will be a wildcard route.
  22. We pushed the routing concept to supports nested routes.[CLICK] By having a directory with the same name of a file, it opens the possibility to create child routes.[CLICK] The will be rendered only when the url will match its path.
  23. To navigate between the pages, we added a component called nuxt-link
  24. This is how it looks like to create a link
  25. To navigate to the about page, We add the to attribute. [CLICK] It’s usage is the same as router-link since we use vue-router under the hood
  26. Supports async/await
  27. Every web application needs to make API calls which are asynchronous. That’s why, like next.js, we added a hook in the pages component to handle this issue.
  28. Let’s start with a simple template
  29. We display a list of posts by showing the title of every post
  30. We now add our list of posts in our data hook. But this is not asynchronous
  31. First, let's rename our data method to asyncData
  32. We also add the async keyword to use await inside since Nuxt transpiles ES6
  33. We need to import axios to make an API call. Axios lets us make HTTP request to both client-side and server-side with the same api.
  34. We can now fetch our API to get the list of posts and display it.
  35. Let’s see how it looks like
  36. Nuxt passes a context object to the asyncData method which helps to in many ways
  37. First, we have some helpers like isClient, isServer and isDev which are boolean and guide you to know where the method is run. We have the env property that you can define in the config file.
  38. Then we have the route property, which is an instance of vue-router, params and query if you want to get informations from the current url. We also have store, but we will see this property later.
  39. To finish, we have our 2 properties from our node.js server, only available when we render the page from the server of course. And 2 methods, one to redirect to another page and error to display the error page.
  40. Let’s see an example, I want a page to display the current user agent, this is how I can do it in nuxt, if req is available, so I’m on the server, I get it from the headers, otherwise I get it from the navigator object available on client-side.
  41. We added a Layout concept in Nuxt
  42. First, we create a layouts directory in our application
  43. We can change the default layout for every page by creating a default.vue component. We simply add the nuxt component to render our current page.
  44. Let’s create a custom layout called dark.vue which encapsulate our page in a container with the dark-mode class.
  45. Then, I can tell for a specific page which layout I want to use with the layout property.
  46. Let’s see a quick example.
  47. Every big application needs a global state for every pages. So we added the store concept [CLICK] based on VUEX.
  48. We add a store directory first.
  49. Then we simply export a state object, here with a count property at 0. [CLICK] Now let’s display the count property in our index page. [CLICK] And also in our about page.
  50. We now add a mutation to increment our count property. [CLICK] We update our about page to add a button which call the increment mutation every time we click on it. [CLICK]
  51. Let’s see how it looks like on now.
  52. We added a special action called nuxt server init which is called by the server before rendering the application. It may useful to store the connected user or fetch some global data and make it available on client-side directly.
  53. Another concept, but for me pretty useful, is the middleware.
  54. Same philosophy, we add a middleware directory.
  55. A middleware is only a method which receive the context and can be asynchronous. Here we simply check our user is connected, otherwise we redirect the user to the login page.
  56. In the page we want to display only to connected user, we add the middleware property and give our auth middleware.
  57. This is a schema to represent what’s happening on an incoming request. The nuxtServerInit is called first if the store is available, then the middleware chain, the validate method that we did not see here, the asyncData & fetch method and then we render our application.
  58. Let’s see a quick demo!
  59. Nuxt is fully customisable with a nuxt.config.js file. With this file, we can modify the webpack & babel configuration, add vue plugins and more.
  60. Head elements are important for any web page, mostly when server-rendered. [CLICK] We use vue-meta to handle this logic via a head property available in the config file, layouts or any pages.
  61. I believe this example is explicit enough to understand how it works.
  62. One powerful way of using Nuxt.js is to use it programmatically
  63. Simply require nuxt, and create a new instance of it by giving it the configuration it needs. The call the build() method and you’re ready to render every route you want.
  64. Also, you can combine it with express by using it as a middleware.
  65. Let’s see how we can deploy any nuxt.js application. [CLICK] With now
  66. We add 2 script, one for building the app for production, we call nuxt build, and the one to start in production mode, called nuxt start.
  67. Then we go to our terminal, in our app folder, and we launch `now` command. [CLICK] And that’s it, your app is up and running on the cloud.
  68. Nuxt can also be used as a static generator for your website, that’s actually what we do to serve our documentation on nuxtjs.org. [CLICK] The command is called `nuxt generate`
  69. You can add a nom script to call `nuxt generate` directly.
  70. This command will actually server-render every route and save it to an HTML file in a folder structure that correspond to each route. It will also put all of theses files in a dist/ folder.
  71. Since now can host static website, we can also deploy our static generated web application by running `now dist`. [CLICK] And…that’s it!
  72. The project is hosted on Github. [CLICK] Right now we are at the version 0.10.6 but we are working on releasing the 1.0 beta pretty soon. [CLICK] We add more than 30 contributors, thank you to all of them. [CLICK] We have 100% of code coverage. [CLICK] More than 500 issues closed, big thanks to our community to help us on theses issues. [CLICK] Also, more than 30 examples to use Nuxt with Vue plugins, Express, Koa, Adonis and more. [CLICK] And all of this, in 6 months.
  73. We have a documentation website on nuxtjs.org. [CLICK] Right now, it has been translated in 5 different languages, English, Russian, Chineese, Japanese en Koean. [CLICK] We have 2 new languages on their way, French and Spanish. [CLICK] A lot of people from different countries are reading it. [CLICK] And it has been made with NuxtJS.
  74. I have to thanks a million time my brother, which is the co-author of Nuxt, he came with the static generation feature. He helped me in the vision of Nuxt, and the biggest part: maintaining it! If you have the chance to work with your brother of sister on a project, do it!
  75. So What’s next apart of the 1.0 release. [CLICK] I would like to introduce the concept of Versatile Web application. It gives you control of what you want to server render or not in your application. [CLICK] It will be a simple property called ssr, default to true. [CLICK] You will be able to set it to false for the whole app. [CLICK] A custom layout, for example the back office. [CLICK] Or a specific page.
  76. With my brother, we are working on other open source projects that we will announce soon. [CLICK] You can be notified on our website orion.sh, I recommend you to take a look at it.
  77. Thank you very much for you time!