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:13:35 +00:00
|
|
|
data() {
|
2017-08-24 10:38:46 +00:00
|
|
|
return {
|
|
|
|
canRender: false
|
|
|
|
}
|
|
|
|
},
|
2017-11-21 12:13:35 +00:00
|
|
|
mounted() {
|
2017-08-24 10:38:46 +00:00
|
|
|
this.canRender = true
|
|
|
|
},
|
2017-11-21 12:13:35 +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:13:35 +00:00
|
|
|
throw new Error('[vue-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:13:35 +00:00
|
|
|
return h(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
class: ['no-ssr-placeholder']
|
|
|
|
},
|
|
|
|
this.placeholder
|
|
|
|
)
|
2017-08-24 10:38:46 +00:00
|
|
|
}
|
|
|
|
}
|