1. const map = new WeakMap()
    2. export default {
    3. name: 'lazy-component',
    4. functional: true,
    5. props: {
    6. show: {
    7. type: Boolean,
    8. default: false
    9. }
    10. },
    11. render (h, context) {
    12. const children = context.children
    13. const hasTarget = map.has(children)
    14. if (!hasTarget && context.props.show) {
    15. map.set(children, true)
    16. }
    17. if (hasTarget) {
    18. return h('div', context.data, context.children)
    19. } else {
    20. return h('div', context.data, [])
    21. }
    22. }
    23. }
    1. // 使用
    2. <create-once :show="showOrNot">
    3. <custom-component/>
    4. </create-once>