首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >替换插槽指令的Vue.js v-slot指令

替换插槽指令的Vue.js v-slot指令
EN

Stack Overflow用户
提问于 2021-04-20 12:12:49
回答 1查看 130关注 0票数 0

我正在尝试模仿在父组件中使用slot标记的默认行为。当我使用<template v-slot>时,内容不会自动转到那里。在不使用slot标签的情况下,正确的方法是什么?因为我读到这个标签会被折旧。谢谢

EN

回答 1

Stack Overflow用户

发布于 2021-04-20 12:57:51

实际上,是slot 属性deprecated (而不是built-in component)。

在v2.6之前,slot属性用于指定给定内容的槽名,slot-scope接收槽属性:

代码语言:javascript
复制
<base-layout>
  <template slot="header" slot-scope="{ subtitle }">
    <h1>Here might be a page title</h1>
    <h2>{{ subtitle }}</h2>
  </template>

  <p>A paragraph for the main content.</p>
  <p>And another one.</p>

  <template slot="footer">
    <p>Here's some contact info</p>
  </template>
</base-layout>

从v2.6开始,这两个属性被v-slot directive组合/替换,其中插槽名称作为参数给出,任何插槽属性都在绑定值中接收:

代码语言:javascript
复制
<base-layout>
  <template v-slot:header="{ subtitle }">
    <h1>Here might be a page title</h1>
    <h2>{{ subtitle }}</h2>
  </template>

  <p>A paragraph for the main content.</p>
  <p>And another one.</p>

  <template v-slot:footer>
    <p>Here's some contact info</p>
  </template>
</base-layout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67172357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档