Nuxt/lib/app/components/no-ssr.js

30 lines
673 B
JavaScript
Raw Normal View History

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