Skip to content

Commit

Permalink
feat: add component ClientOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed May 14, 2019
1 parent 3b4d1cb commit 391183c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/saber/vue-renderer/app/components/ClientOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
name: 'ClientOnly',
functional: true,
render (h, { parent, children }) {
if (parent._isMounted) {
return children
} else {
parent.$once('hook:mounted', () => {
parent.$forceUpdate()
})
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
export default {
name: 'layout-manager',
name: 'LayoutManager',
functional: true,
inject: ['layouts'],
render(
Expand Down
4 changes: 3 additions & 1 deletion packages/saber/vue-renderer/app/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import Vue from 'vue'
import layouts from '#cache/layouts'
import createRouter from './router'
import Meta from './vendor/vue-meta'
import Layout from './LayoutManager.vue'
import Layout from './components/LayoutManager.vue'
import ClientOnly from './components/ClientOnly'
import extendBrowserApi from '#cache/extend-browser-api'
import injectConfig from './helpers/inject-config'
import setTransition from './helpers/set-transition'

Vue.config.productionTip = false

Vue.component(ClientOnly.name, ClientOnly)
Vue.component(Layout.name, Layout)

Vue.use(Meta, {
Expand Down
15 changes: 15 additions & 0 deletions website/pages/docs/components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Components
layout: docs
---

Saber registered a set of Vue components by default.

## `SaberLink`

A drop-in replacement for Vue Router's `<router-link>` component, we added addtional features like prefetching route components.

## `ClientOnly`

Use this component to wrap non SSR friendly components.

1 change: 1 addition & 0 deletions website/saber-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = {
title: 'References',
children: [
{ title: 'Saber Config', link: '/docs/saber-config.html' },
{ title: 'Built-in Components', link: '/docs/components.html' },
{ title: 'Plugin API', link: '/docs/plugin-api.html' },
{ title: 'Saber Instance', link: '/docs/saber-instance.html' },
{ title: 'Saber Browser APIs', link: '/docs/browser-apis.html' },
Expand Down

0 comments on commit 391183c

Please sign in to comment.