vue 2.0 scopedSlots和slots在render函数中的应用示例

渲染内容为:

hello from functional render scopedSlots

render scopedSlots

named slot of render

hello from functional render scopedSlots

functional render scopedSlots

named slot of functional render

源码:

<!DOCTYPE html>
<html lang='zh'>
<head>
  <title></title> 
</head>
<body>
  <div id="app">

  <rrr>
    <p slot="static"> named slot of render</p>
    <template slot="scp" scope="props">
      <p>hello from functional render scopedSlots</p>
      <p>{{ props.text }}</p>
    </template>
  </rrr>

<hr>

  <fff>
    <p slot="static"> named slot of functional render</p>
    <template slot="scp" scope="props">
      <p>hello from functional render scopedSlots</p>
      <p>{{ props.text }}</p>
    </template>
  </fff>


  </div>
<script src="https://cdn.staticfile.org/vue/2.3.2/vue.js"></script>
<script>


Vue.component('rrr', {
  render: function (h) {
    var children = this.$scopedSlots.scp({text:"render scopedSlots"})
    children = children.concat(this.$slots.static)
    return h('div',children)
  },
})

Vue.component('fff', {
  functional: true,
  render: function (h, ctx) {
    var children = ctx.data.scopedSlots.scp({text:"functional render scopedSlots"})
    children = children.concat(ctx.slots().static)
    return h('div',children)
  },
})


var app = new Vue({
}).$mount('#app')
</script>
</body>
</html>

转载于:https://www.cnblogs.com/xiangnan/p/6909721.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值