您当前的位置: 首页 > 

66Vue - Slots 分发内容(具名Slots)

杨林伟 发布时间:2019-07-29 11:33:04 ,浏览量:3

元素可以用一个特殊的属性 name 来配置如何分发内容。多个 slot 可以有不同的名字。具名 slot 将匹配内容片段中有对应 slot 特性的元素。

仍然可以有一个匿名 slot ,它是默认 slot ,作为找不到匹配的内容片段的备用插槽。如果没有默认的 slot ,这些找不到匹配的内容片段将被抛弃。

例如,假定我们有一个 app-layout 组件,它的模板为:

父组件模版:


  Here might be a page title
  

A paragraph for the main content.

And another one.

Here's some contact info

渲染结果为:

Here might be a page title

A paragraph for the main content.

And another one.

Here's some contact info

在组合组件时,内容分发 API 是非常有用的机制。

关注
打赏
1688896170
查看更多评论

杨林伟

暂无认证

  • 3浏览

    0关注

    3183博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0958s