vue.js - 带有命名插槽的 Vue 布局
问题描述
可能吗?我有这样的事情:
<template>
<my-layout>
<template #header>
Some header html goes here
</template>
Body html here
</my-layout>
</template>
<script>
import MyLayout from './MyLayout.vue'
export default {
layout: MyLayout,
components: {
//MyLayout
}
}
</script>
和这样的模板
<template>
<div>
<slot name="header"/>
</div>
<slot/>
</template>
默认插槽有效,但“标题”插槽不显示自身(除非使用 MyLayout 作为标准组件)。
解决方案
我认为您提供的模板上的结束标签有问题,应该如下所示:
<template>
<div>
<slot name="header"> </slot>
</div>
</template>
之后,layout 属性只排除字符串或返回字符串的函数,因此 parent 应如下所示:
<template>
<my-layout>
<template #header>
Some header html goes here
</template>
Body html here
</my-layout>
</template>
<script>
import MyLayout from "./MyLayout.vue";
export default {
layout: "MyLayout",
components: {
//MyLayout
}
};
</script>
我希望这可以解决您的问题并度过愉快的一天:)
推荐阅读
- sql - 两个模式之间的 Redshift 提取字符串 (regexp_substr)
- javascript - 修改父prototype.init()函数
- teamcity - 通过 TeamCity/Octopus 部署 ASP.NET 应用程序时,Application Insights 停止工作
- javascript - 使用 MomentJS 将 ISO 8601 转换为不同的 ISO 8601 格式
- substring - PowerBI DAX:在不重复 ID 的情况下计算变量的几个因素
- c# - 在表单关闭时等待任务完成
- java - 为什么在 FirefoxDriver() 驱动的 get() 方法中总是需要提到 http;//?
- scala - 如何让代码更短?
- lua - Roblox 异地传送问题
- continuous-deployment - TFS 部署代理运行远程 powershell 问题