Skip to content

Instantly share code, notes, and snippets.

@mercs600
mercs600 / fetch-blog-index.js
Created April 4, 2020 14:30
nuxt-exercise-5-fetch-blog-errorHandler
export default {
data () {
return {
posts: []
}
},
watch: {
'$fetchState.error' (error) {
// do something with error
console.log(error)
@mercs600
mercs600 / fetch-blog-_id.html
Last active April 4, 2020 14:02
nuxt-exercise-5-fetch-error_template
<template>
<div>
<div v-if="$fetchState.pending">
<content-placeholders>
<content-placeholders-heading/>
<content-placeholders-text :lines="3" />
</content-placeholders>
</div>
<div v-if="$fetchState.error">
<h1>{{ $fetchState.error.statusCode }} An error occurred: {{ $fetchState.error.message }}</h1>
@mercs600
mercs600 / fetch-blog-index.js
Created March 31, 2020 19:54
nuxt-exercise-5-fetch-timestamp
export default {
data () {
return {
posts: []
}
},
activated() {
// Call fetch again if last fetch more than 30 sec ago
if (this.$fetchState.timestamp <= (Date.now() - 30000)) {
this.$fetch()
@mercs600
mercs600 / layouts-default.html
Created March 31, 2020 19:32
nuxt-exercise-5-keep-alive
<template>
<div class="container">
<nuxt keep-alive />
</div>
</template>
@mercs600
mercs600 / nuxt.config.js
Created March 31, 2020 19:06
nuxt-exercise-5-nuxt-config
export default {
/*
** Plugins to load before mounting the App
*/
plugins: [
'@/plugins/vue-content-placeholders.js'
]
}
@mercs600
mercs600 / vue-content-placeholders.js
Created March 31, 2020 19:01
nuxt-exercise-5-vue-content-placeholdes.js
import Vue from 'vue'
import VueContentPlaceholders from 'vue-content-placeholders'
Vue.use(VueContentPlaceholders)
@mercs600
mercs600 / fetch-blog_id.html
Last active March 31, 2020 19:08
nuxt-exercise-4-fetch-blog-_id.html
<template>
<div>
<div v-if="$fetchState.pending">
<content-placeholders>
<content-placeholders-heading/>
<content-placeholders-text :lines="3" />
</content-placeholders>
</div>
<div v-if="post">
<h1>{{ post.title }}</h1>
@mercs600
mercs600 / fetch-blog-_id.vue
Created March 31, 2020 12:36
nuxt-exercise-5-fetch-blog-id.vue
<template>
<div v-if="post">
<h1>{{ post.title }}</h1>
<div>{{ post.body }}</div>
<nuxt-link to="/fetch-blog">back to list</nuxt-link>
</div>
</template>
<script>
export default {
data () {
@mercs600
mercs600 / fetch-blog-_index.vue
Created March 31, 2020 12:27
nuxt-exercise-5-fetch-blog-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="`/fetch-blog/${post.id}`">{{ post.title }}</nuxt-link>
</div>
</div>
@mercs600
mercs600 / nuxt-ssr-exercise-4.html
Created March 29, 2020 15:14
nuxt-ssr-exercise-4-ssr-results
<div data-server-rendered="true" id="__nuxt"><!----><!----><div id="__layout"><div class="container"><div data-fetch-key="0"><h1> fetch method </h1> <p> Just check HTML source or inspect window.__NUXT__ </p></div></div></div></div><script>window.__NUXT__={layout:"default",data:[{}],fetch:[{title:"fetch method"}],error:null,state:{},serverRendered:true,routePath:"\u002Ffetch-basic",logs:[]};</script>