首页 > 其他 > 详细

Vue-Render函数理解示例

时间:2017-04-13 15:13:53      阅读:403      评论:0      收藏:0      [点我收藏+]

对应文档节点: https://vuefe.cn/v2/guide/render-function.html#Slots

<body>
    <div id="app">
        <div class="parent">
            <anchored-heading>
            </anchored-heading>
        </div>
    </div>
</body>

<script>
    Vue.component(child, {
        render: function (createElement) {
            // <div><slot :text="msg"></slot></div>
            //debugger;
            return createElement(div, [
                this.$scopedSlots.default({
                    text: this.msg
                })
            ])
        },
        // template: `
        //     <div class="child">
        //         <slot :text="msg"></slot>
        //     </div>
        // `,
        data: function () {
            return {
                msg: "Demo"
            }
        }

    });

    Vue.component(anchored-heading, {
        render(createElement) {
            return createElement(div, [
                createElement(child, {
                    // pass scopedSlots in the data object
                    // in the form of { name: props => VNode | Array<VNode> }
                    scopedSlots: {
                        default: function (props) {
                            debugger;
                            return createElement(span,hello-+ props.text)
                        }
                    }
                })
            ])
        },
        // template: `
        //     <div class="parent">
        //         <child>
        //             <template scope="props">
        //             <span>hello {{ props.text }}</span>
        //             </template>
        //         </child>
        //     </div>
        // `
    })

    new Vue({
        el: "#app"
    });
</script>

 

Vue-Render函数理解示例

原文:http://www.cnblogs.com/wipphj/p/6703953.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!