Nuxt入门之client-only原理

仓库:vue-client-only/index.js at master · egoist/vue-client-only · GitHub


1.简介

client-only用于在ssr中指定组件在客户端渲染

2.原理

export default {
  name: 'ClientOnly',
  functional: true,
  props: {
    placeholder: String,
    placeholderTag: {
      type: String,
      default: 'div'
    }
  },
  render(h, { parent, slots, props }) {
    const { default: defaultSlot = [], placeholder: placeholderSlot } = slots()

    if (parent._isMounted) {
      return defaultSlot
    }

    parent.$once('hook:mounted', () => {
      parent.$forceUpdate()
    })

    if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
      return h(
        props.placeholderTag,
        {
          
上一篇:大型情感类技术连续剧-徒手撸一个 uTools(一)


下一篇:尚硅谷_在线教育_Nuxt整合错误