【发布时间】:2018-08-15 14:17:38
【问题描述】:
我正在尝试了解 <slot> 在 Vue 模板中的用法。据我了解,插槽可用于将组件中的子内容传递给模板。
下面是一个简短的、最小的工作示例 (also on codepen)。
Vue.component('mine', {
template: '#mine'
})
var app = new Vue({
el: '#app'
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.min.js"></script>
<script type="text/x-template" id="mine">
<h1>this is it</h1>
<slot></slot>
</script>
<div id="app">
<mine>
<p>why isn't this displayed</p>
</mine>
</div>
我希望输出是这样的:
<h1>this is it</h1>
<p>why isn't this displayed</p>
但是,当页面被渲染时,第二行没有出现。
【问题讨论】:
-
试试
标签: vue.js vue-component