Skip to content

Instantly share code, notes, and snippets.

@mercs600
mercs600 / 0_reuse_code.js
Created July 14, 2016 12:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mercs600
mercs600 / asyncData-basic.vue
Last active March 27, 2020 15:29
nuxt-ssr-excercise-1
<template>
<div>
<h1> {{ title }} </h1>
<p> Just check HTML source or inspect window.__NUXT__ </p>
</div>
</template>
<script>
export default {
asyncData (context) {
// will be merged with data object,
@mercs600
mercs600 / asyncData-basic.html
Last active March 27, 2020 16:00
nuxt-ssr-excercise-1-result
<div data-server-rendered="true" id="__nuxt"><!----><!----><div id="__layout"><div class="container"><div><h1> async data </h1> <p> Just check HTML source or inspect window.__NUXT__ </p></div></div></div></div>
<script>window.__NUXT__={layout:"default",data:[{title:"async data"}],fetch:[],error:null,state:{},serverRendered:true,routePath:"\u002FasyncData-basic",logs:[]};</script>
@mercs600
mercs600 / asyncData-context.vue
Last active March 27, 2020 17:58
nuxt-ssr-excercise-2
<template>
<div>
<h1> Context usage </h1>
<div v-if="isMacOS">
Content for MacOS
</div>
<div v-else-if="isWindows">
Content for Windows
</div>
<div v-else>
@mercs600
mercs600 / asyncData-context.html
Created March 27, 2020 18:07
nuxt-ssr-excercise-2-results
<div data-server-rendered="true" id="__nuxt"><!----><!----><div id="__layout"><div class="container"><div><h1> Context usage </h1> <div>
Content for MacOS
</div></div></div></div></div><script>window.__NUXT__=(function(a){return {layout:"default",data:[{isWindows:false,isMacOS:a}],fetch:[],error:null,state:{},serverRendered:a,routePath:"\u002FasyncData-context",logs:[]}}(true));</script>
@mercs600
mercs600 / asyncData-blog-index.vue
Last active March 28, 2020 15:22
nuxt-ssr-exercise-3_index
<template>
<div>
<h1> Blog posts </h1>
<div v-if="posts && posts.length">
<div
v-for="post in posts"
:key="post.id">
<nuxt-link :to="`/asyncData-blog/${post.id}`">{{ post.title }}</nuxt-link>
</div>
</div>
@mercs600
mercs600 / asyncData-blog-_id.vue
Last active March 28, 2020 17:00
nuxt-ssr-exercise-3_id.vue
<template>
<div>
<h1> {{ post.title }} </h1>
<div> {{ post.body }} </div>
<nuxt-link to="/asyncData-blog">back to list</nuxt-link>
</div>
</template>
<script>
export default {
asyncData: ({ $http, params }) => $http
@mercs600
mercs600 / asyncData-blog-_id.js
Last active March 28, 2020 17:06
nuxt-ssr-exercise-3_error-handle
export default {
asyncData: ({ $http, params, error }) => $http
.$get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
.then(post => ({ post }))
.catch(err => error(err))
};
@mercs600
mercs600 / layouts-error.vue
Last active March 29, 2020 14:31
nuxt-ssr-exercise-3_error.vue
<template>
<div class="container">
<h1 v-if="error.statusCode === 404">Page not found</h1>
<h1 v-else>{{ error.statusCode }} An error occurred: {{ error.message }}</h1>
<nuxt-link to="/">Home page</nuxt-link>
</div>
</template>
<script>
export default {
@mercs600
mercs600 / fetch-basic.vue
Last active March 29, 2020 15:19
nuxt-ssr-exercise-4-fetch
<template>
<div>
<h1> {{ title }} </h1>
<p> Just check HTML source or inspect window.__NUXT__ </p>
</div>
</template>
<script>
export default {
data () {
return {