javascript - 表格中的 vue 可拖动宽度有问题吗?

标签 javascript vue.js vuejs2 draggable bulma

我正在使用 vuedraggable在 Bulma 表中,但它会产生样式问题:

screenshot

这不是 bool 玛表的问题。我在自己的表中使用了它,但出现了同样的问题。

这是我的代码:

<table class="table is-fullwidth is-bordered">
    <thead>
        <tr>
            <th></th>
            <th>Name</th>
            <th>brand</th>
            <th>Date Created</th>
            <th colspan="2">Actions</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th></th>
            <th>Name</th>
            <th>brand</th>
            <th>Date Created</th>
            <th colspan="2">Actions</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td colspan="5" v-if="featureds.length == 0">0 Models Found</td>
        </tr>
        <draggable v-model="furds" :options="{group:'furds'}" @start="drag=true" @end="drag=false" @change="onChnage">

            <tr class="dragndrop" v-for="featured in furds">
                <td class="drag-icon"><i class="fa fa-arrows"></i></td>
                <td>{{ featured.name }}</td>
                <td>{{ featured.brand.name }}</td>
                <td>{{ featured.created_at | moment("MMMM Do, YYYY") }}</td>
                <td><a :href="`/manage/featured/${featured.id}`">View</a></td>
                <td><a :href="`/manage/featured/${featured.id}/edit`">Edit</a></td>
            </tr>
        </draggable>
    </tbody>
</table>

最佳答案

不是用 draggable 包装 tr,而是将 tbody 作为可拖动元素传递。

<draggable element="tbody" v-model="furds">

查看链接以获得更好的理解: https://jsfiddle.net/dede89/L54yu3L9/ (带表格的例子)(在vue draggable官方文档中找到)

[[更新:完整代码(基于问题)]]

<table class="table is-fullwidth is-bordered">
    <thead>
        <tr>
            <th></th>
            <th>Name</th>
            <th>brand</th>
            <th>Date Created</th>
            <th colspan="2">Actions</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th></th>
            <th>Name</th>
            <th>brand</th>
            <th>Date Created</th>
            <th colspan="2">Actions</th>
        </tr>
    </tfoot>
    <draggable element="tbody" v-model="furds"> <!-- change here -->
        <tr>
            <td colspan="5" v-if="featureds.length == 0">0 Models Found</td>
        </tr>
            <tr class="dragndrop" v-for="featured in furds">
                <td class="drag-icon"><i class="fa fa-arrows"></i></td>
                <td>{{ featured.name }}</td>
                <td>{{ featured.brand.name }}</td>
                <td>{{ featured.created_at | moment("MMMM Do, YYYY") }}</td>
                <td><a :href="`/manage/featured/${featured.id}`">View</a></td>
                <td><a :href="`/manage/featured/${featured.id}/edit`">Edit</a></td>
            </tr>
        </draggable>
</table>
<script>
import draggable from "vuedraggable";
  export default {
      components: {
      draggable
    },
...
}
</script>

关于javascript - 表格中的 vue 可拖动宽度有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53189573/

相关文章:

javascript - 如何过滤该数组中大于或等于 90 的标记?

javascript - 在 Electron 中要求和扩展类,怎么做?

javascript - 正则表达式无效 : Invalid group

file-upload - 如何在vue js中使用Filepond并使用axios上传文件?

javascript - 当 Bootstrap 模式关闭时,我如何知道单击了哪个按钮?

javascript - 在 Vue.js 3 setup() 中访问 this.$root

vue.js - 在计算属性中访问 $el

javascript - 如何在 .vue 文件的 &lt;script&gt; 部分的父组件中处理通过 this.$emit 发出的自定义子事件?

javascript - 合并具有相同第一个键值的对象,因此其余键值将添加到合并对象中

javascript - 在 v-select 中输入自定义文本