@aleksejdix
<div id="app"></div>
@aleksejdix
CONS:
PROS:
REQUEST
RESPONSE
SERVER
CLIENT
1. HTTP
REQUEST
HTTP
RESPONSE
SERVER
API
AJAX
REQ
AJAX
RES
REQ
RES
initial
rendered
@aleksejdix
no
yes
@aleksejdix
LIMITS:
npx create-nuxt-app <project-name>
yarn create nuxt-app <project-name>
<template>
<h1>
Hello, Zurich!
</h1>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
import Vue from 'vue'
import Router from 'vue-router'
const _94b0fd58 = () => import('../pages/index.vue')
Vue.use(Router)
export function createRouter() {
return new Router({
mode: 'history',
routes: [{
path: "/",
component: _94b0fd58,
name: "index"
}]
})
}
Hello, Zurich!
<body data-n-head="">
<div data-server-rendered="true" id="__nuxt">
<h1>Hello, Zurich!</h1>
</div>
</body>
<script>
export default {
data() {
return {
speakers: []
}
},
async mounted() {
const speakers = await axios.$get('/speakers')
this.speakers = speakers
}
}
</script>
<div id="app"></div>
export default {
asyncData(context) {}
fetch(context) {}
nuxtServerInit(store, context) {}
}
no `this`, but `context`
export default {
async asyncData() {
const speakers = await axios
.$get('/speakers')
return {
speakers
}
}
}
<script>
window.__NUXT__=(function(a){
return {
layout: "default",
data: [{
speakers: [{
id:"cjnirn6wim84h0932hrvvrc82",
name: "Martin"
}]
}],
error: null,
serverRendered:true
}
}(400));
</script>
<div id="app">
<h1>Martin</h1>
</div>
<template>
<form @submit.prevent="askServer">
<input type="search" v-model="search"/>
<button>search<button>
</form>
</template>
?search=GETPARAMS
REQUEST
RESPONSE
SERVER
domain.com/speakers?sort=DESC
will resolve your REST API request and send sorted data back to the client
export default {
data() {
return {
page: ''
}
},
watch: {
'$route.query.page'(page) {
this.page = page
this.submit()
}
}
}
async asyncData(context) {
const { speaker } = await context
.$axios
.$get(context.route.params.id)
return { speaker }
}
export default {
head () {
return {
title: 'Aleksej Dix - webzueri.ch',
meta: [
{
hid: 'description',
name: 'description',
content: 'Front-end Developer and webzurich organizer'
}
]
}
}
}