一、默认插槽
创建默认插槽的代码如下,很简单,你只需要把 this.$slots.default 理解为一个创建默认插槽时,由vue提供的全局静态变量即可。直接拿来用。
Vue.component("slot_render",{
render: function (createElement) {
return createElement('div',[this.$slots.default])
}
})
<div id="slot_render_demo">
<slot_render>
默认插槽
</slot_render>
</div>
二、命名插槽
创建命名插槽的代码如下,也很简单,最关键的是插槽名字:this.$slots.slot_name1,这个名字(slot_name1)是自己随便取的,然后在使用的时候要对应起来即可。
Vue.compon