feature: Add no-ssr component

This commit is contained in:
Sebastien Chopin 2017-08-24 12:38:46 +02:00
parent cfd8673a54
commit fb25c982a7
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,28 @@
/*
** From https://github.com/egoist/vue-no-ssr
** With the authorization of @egoist
*/
export default {
name: 'no-ssr',
props: ['placeholder'],
data () {
return {
canRender: false
}
},
mounted () {
this.canRender = true
},
render (h) {
if (this.canRender) {
if (
process.env.NODE_ENV === 'development' &&
this.$slots.default.length > 1
) {
throw new Error('<no-ssr> You cannot use multiple child components')
}
return this.$slots.default[0]
}
return h('div', { class: { 'no-ssr-placeholder': true } }, this.placeholder)
}
}

View File

@ -2,6 +2,7 @@ import 'es6-promise/auto'
import Vue from 'vue'
import Meta from 'vue-meta'
import { createRouter } from './router.js'
import NoSSR from './components/no-ssr.js'
import NuxtChild from './components/nuxt-child.js'
import NuxtLink from './components/nuxt-link.js'
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./components/nuxt-error.vue" %>'
@ -12,6 +13,9 @@ import { getContext, getLocation } from './utils'
<% plugins.forEach(plugin => { %>import <%= plugin.name %> from '<%= plugin.name %>'
<% }) %>
// Component: <no-ssr>
Vue.component(NoSSR.name, NoSSR)
// Component: <nuxt-child>
Vue.component(NuxtChild.name, NuxtChild)

View File

@ -195,6 +195,7 @@ export default class Builder extends Tapable {
'components/nuxt-child.js',
'components/nuxt-link.js',
'components/nuxt.vue',
'components/no-ssr.js',
'views/app.template.html',
'views/error.html'
]