im using this solution to set table cells in a vuejs component dynamically:
http://forum.vuejs.org/topic/526/repeating-table-row-with-slot
This works just with Vue.js v1.0.10 but not with the current version v1.0.26.
Jsfiddle: https://jsfiddle.net/peL8fuz3/
I'm trying to get the following markup (the item object should be available in the component)
<div id="vue">
<basic-table>
<table-cell>{{ item.id }}</table-cell>
<table-cell>{{ item.title }}</table-cell>
</basic-table>
</div>
Vue.js component (more at the fiddle)
Vue.component('basic-table', {
template: '<table><tbody><tr v-for="item in collection" v-slot></tr></tbody></table>',
data: function () {
return {
collection: [
{id: 1, title: 'Vue'},
{id: 2, title: 'Vue 2'},
{id: 3, title: 'Vue 3'},
{id: 4, title: 'Vue 4'},
]
}
}
});
Anyone knows how to solve this?
Edit Didnt found a working solution yet - still searching..
Scoped slots To pass a property in Vue, you would define the data in the parent component and assign a value to the data. Then, you'd pass the value of the property to the child component so the data becomes a property in the child component.
v-slot is used on an HTML element. v-slot can only be used on a <template> element or the component receiving the slot. Otherwise, Vue throws a compile error. See Example 1 below. v-slot is used on a component, but the component has another <template v-slot> as a child.
So in the most basic sense when you want to use slots in VueJS, you add the <slot></slot> tags in the child component where you expect to receive data from outside. Slot is a reserved keyword in VueJs and as soon as it sees that markup, it does it's thing to render the content that is being passed from the outside.
Scoped slots are exactly like regular slots, with the difference that we pass data from the child component to the parent component. This data can then be used inside the slot content.
That's quite hard to find out what exactly gone wrong, but that code was broken since v1.0.18. I was unable to dig deeper to eliminate exact commit but there was a couple of optimizations made which potentially could affect $context._content
rendering.
However you can solve your problem by changing
var raw = host.$options._content;
to
var raw = host._context._directives.filter(function (value) {
return !(value.Component === undefined);
})[0].el;
That change is compatible with v1.0.26. You can find fixed code here.
I was failed to find a way to achieve the same result using public API. So this solution is also relies on non-public API thus may break in future release.
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