I have a template that loops using v-for. In the template I have a named slot with the name being dynamically assigned in the loop. No content is appearing, what am I doing wrong?
<todo-tabs :list="items">
<div slot="interview">Interview</div>
<div slot="membership">Membership</div>
<div slot="profile">Profile</div>
<div slot="handoff">Handoff</div>
</todo-tabs>
<template id="todo-tabs">
<div class="tab-content ">
<div v-for="item in list" :class="{'active': item.current}" class="tab-pane" id="@{{ item.id }}">
<div class="skin skin-square">
<form class="form-horizontal" role="form">
<div class="form-body">
<slot name="@{{ item.id }}"></slot>
</div>
<div class="form-actions">
<button type="submit" class="btn red btn-outline">Submit</button>
<button type="button" class="btn default">Cancel</button>
</div>
</form>
</div>
</div>
</div>
</template>
<script>
Vue.component('todo-tabs', {
template: '#todo-tabs',
props: ['list']
});
var vm = new Vue({
el: "#todo",
data: {
items : [
{id: 'interview', name: 'interview', complete: true, body: 'something1', step_content: 'SOME' },
{id: 'membership', name: 'membership', complete: false, body: 'something2', step_content: 'SOME' },
{id: 'profile', name: 'profile', complete: false, body: 'something3', step_content: 'SOME', current: true },
{id: 'handoff', name: 'handoff', complete: false, body: 'something4', step_content: 'SOME'}
]
}
});
</script>
In VueJs version 2.1.3 you can use this:
parent:
<div v-for="row in rows">
<slot name="buttons" :row="row"></slot>
</div>
child:
<template slot="buttons" scope="props">
<a href="props.row.href">go there</a>
</template>
This construction does not generate any warning, therefor i think its valid.
https://vuejs.org/v2/guide/components.html#Scoped-Slots
in VueJS 1.0.16 you could do this in your template:
<div v-for="item in tiems">
<slot :name="item.id"></slot>
</div>
However, as of 1.0.17 VueJS throws this error: <slot :name="item.id">: slot names cannot be dynamic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With