带有道具的内联模板中的Vuejs组件插槽
Vuejs Component slot in inline template with props
我有以下示例代码:这是一个vuejs环境,包含一个名为modal的组件。我想在模态模板内为特定区域添加一个槽,并向该槽添加一个prop值(在本例中为"modalId")。但这并不冷静——什么都不做。
<template id="modalTemplate">
<div class="modal fade" :id="modalId" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">@{{ modalHeader }}</h4>
</div>
<div class="modal-body">
<div v-show="errors !== false" class="alert alert-warning">
<div v-for="error in errors">
@{{ error }}
</div>
</div>
<slot></slot>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" v-on:click="this.$dispatch('handleform', mData)">Save changes</button>
</div>
</div>
</div>
</div>
</template>
<modal v-ref:modal :active="active" error="" v-on:handleform="addMember" modal-id="modalAdd" modal-header="Mitglied hinzufügen" :m-data="newMember">
@{{ modalId | json }}
</modal>
我在Vue上也遇到过这个问题。根据文件,你做得对。因为模板中只有一个<slot>
元素,所以模板中的内容应该插入到<slot>
中。但是什么也没有显示出来。
尝试将<slot></slot>
更改为<content></content>
。我在文档的不同部分看到了这两种方法。
否则,只需为插槽命名即可。类似的东西
<slot name="content"></slot>
然后
<modal v-ref:modal :active="active" error="" v-on:handleform="addMember" modal-id="modalAdd" modal-header="Mitglied hinzufügen" :m-data="newMember">
<span slot="content">@{{ modalId | json }}</span>
</modal>
希望其中一个对你有用。
相关文章:
- 从vuejs中的组件模板访问父方法
- 编辑组件中的Vuejs数据
- 访问Vuejs组件内部的元素
- 带有组件标签的 VueJS 路由不起作用
- 将自定义属性添加到 vuejs 组件
- VueJS组件来运行一个MelonJS游戏
- Vuejs中同级组件之间的通信
- 如何在单文件组件中扩展另一个 VueJS 组件?(ES6 vue-loader)
- Vuejs 在尝试遍历数组数据或 v-for 时无法正确呈现组件
- 有没有在 vuejs 中重置组件初始数据的正确方法
- 如何在 Vuejs 组件中应用过滤器
- 如何使用组件从 vuejs 中获取纯数组
- VueJS - 组件中的组件
- 在VueJS中将父函数传递给子组件
- VueJS在内联模板组件中重新编译HTML
- 带有道具的内联模板中的Vuejs组件插槽
- 为什么我的VueJs组件没有显示在前端
- 一个VueJS组件,带有多个模板
- $el之外的DOM元素的VueJS组件
- Vuejs组件等待facebook sdk加载