简体   繁体   English

vuejs - <slot> 在重复表行

[英]vuejs - <slot> in repeating table row

im using this solution to set table cells in a vuejs component dynamically: 即时使用此解决方案动态设置vuejs组件中的表格单元格:

http://forum.vuejs.org/topic/526/repeating-table-row-with-slot 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. 这适用于Vue.js v1.0.10,但不适用于当前版本v1.0.26。

Jsfiddle: https://jsfiddle.net/peL8fuz3/ 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.js组件(更多小提琴)

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.. 编辑 Didnt找到了一个有效的解决方案 - 仍在搜索..

That's quite hard to find out what exactly gone wrong, but that code was broken since v1.0.18 . 很难找出究竟出了什么问题,但是自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. 我无法深入挖掘以消除确切的提交,但是有一些优化可能会影响$context._content渲染。

Solution

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 . 该更改与v1.0.26兼容。 You can find fixed code here . 你可以在这里找到固定的代码。

Disclaimer 放弃

I was failed to find a way to achieve the same result using public API. 我没有找到使用公共API实现相同结果的方法。 So this solution is also relies on non-public API thus may break in future release. 所以这个解决方案也依赖于非公共API,因此可能会在未来版本中破解。

Aaron, my answer probably is not satisfied for your question but why don't you make it simple as the following code but you have to use directive and all of this stuff ? Aaron,我的回答可能不满意你的问题,但为什么不像下面的代码那样简单,但你必须使用指令和所有这些东西?

I am still figuring why your solution is working on the previous version, not the current version. 我仍然在想为什么你的解决方案在以前的版本上工作,而不是当前的版本。 :D :d

 new Vue({ el: '#vue', data: { items: [{ id: 1, title: 'Vue' }, { id: 2, title: 'Vue 2' }, { id: 3, title: 'Vue 3' }, { id: 4, title: 'Vue 4' }, ] } }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script> <table border="1" class="table" id="vue"> <tbody> <tr v-for="item in items"> <td>{{item.id}}</td> <td>{{item.title}}</td> </tr> </tbody> </table> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM