mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feature: Add no-ssr component
This commit is contained in:
parent
cfd8673a54
commit
fb25c982a7
28
lib/app/components/no-ssr.js
Normal file
28
lib/app/components/no-ssr.js
Normal 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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
||||
|
@ -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'
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user