table.vue

...
        <tbody class="table-body">
            <slot></slot>
        </tbody>
...

TableCellRow.vue

<template>
    <td class="table-row-cell" :class="this.class">
        <slot></slot>
    </td>
</template>

我如何try 使用它:

<my-table>
                <template #default>
                    <tr>
                        <td>i am inside the tr</td> <----- this is inside the <tr>
                            <table-row-cell> <-------- this is outside of the <tr>
                                    i am outside the tr
                            </table-row-cell>
                    </tr>
                </template>
            </my-table>

就像这样:

            <my-table>
                <tr>
                    <td>i am inside the tr</td>
                    <table-row-cell>
                        i am outside the tr
                    </table-row-cell>
                </tr>
            </my-table>

在这个最新的 case 中,这就是我得到的:

<tbody class="table-body"> i am inside the tr <td class="table-row-cell"> i am outside the tr </td></tbody>

在第一种情况下,我得到了这个:

<tbody class="table-body"><tr><td>i am inside the tr</td></tr><td class="table-row-cell"> i am outside the tr </td></tbody>

我也try 过这个:

            <my-table><template #default>
                <tr>
                    <table-row-cell>
                        i am outside the tr
                    </table-row-cell>
                </tr>
            </template>
</my-table>

但我只是得到这个:

<tbody class="table-body"><tr></tr><td class="table-row-cell"> i am outside the tr </td></tbody>

那是怎么回事?我不能使用标签中只有标签的组件?或者是什么问题?如果我将我的组件放置在标签中,为什么它要么抛出并只渲染,要么渲染并将其他所有内容放在标签下面?比如什么?为什么Vue无缘无故地如此困难?

我只是想将a放入自定义表的插槽中,并将自定义组件放入其中-为什么这么困难?我是不是绊倒了还是怎么了?我没有错过一个结束标签,我的组件很好,那么为什么会发生这种情况呢?

我可以用最简单的例子来本地重现这个问题:

<table class="i-am-the-example-table">
            <tbody>
                <tr class="i-am-the-tr-hello">
                    <table-row-cell>
                        i am outside of the TABLE itself, but idk why
                    </table-row-cell>
                </tr>
            </tbody>
        </table>

tableRowCell组件:

<template>
    <td>
        <slot></slot>
    </td>
</template>

全球注册的组件:

import TableRowCell from "./components/custom/Tables/TableRowCell.vue";
app.component("TableRowCell", TableRowCell);

how it looks like on my end: img on my end

推荐答案

由于OP没有使用任何文件夹(因此没有.vue个文件),因此解决办法是这样进行

<tbody>
  <tr is="vue:tab-descgen" ></tr>
</tbody>

归功于answer here.我已经更新了答案,提供了更多详细信息,说明了为什么会发生这种情况,并反映了Vue 3的最新变化!

Javascript相关问答推荐

假设我有2个对象,根据它们,我想要新对象

单击按钮后未清除 Select

强制执行useStatego struct 化变量[foo,setFoo]的命名约定?

react 路由加载程序行为

每次子路由重定向都会调用父加载器函数

如何用显示网格平滑地将元素从一个地方移动到另一个地方?

在Angular中将样式应用于innerHTML

使用GraphQL查询Uniswap的ETH价格

如何避免页面第一次加载时由于CSS样式通过JavaScript更改而出现闪烁

我正在建立一个基于文本的游戏在react ,我是从JS转换.我怎样才能使变量变呢?

制作钢琴模拟器,并且在控制台中不会执行或显示该脚本

编辑文本无响应.onClick(扩展脚本)

是什么导致了这种奇怪的水平间距错误(?)当通过JavaScript将列表项元素追加到无序列表时,是否在按钮之间?

WP Bootstrap NavWaker:下拉菜单一次打开所有下拉菜单

将Node.js包发布到GitHub包-错误ENEEDAUTH

是否可以在Photoshop CC中zoom 路径项?

MongoDB受困于太多的数据

输入的值的类型脚本array.排序()

如何使用抽屉屏幕及其子屏幕/组件的上下文?

我不知道如何纠正这一点.