首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel的Vuedraggable问题

Laravel的Vuedraggable问题
EN

Stack Overflow用户
提问于 2020-07-27 03:28:34
回答 1查看 51关注 0票数 0

我一直想让Vuedraggable和Laravel一起工作一周。我是Vue的新手。

我的控制器将一个$testimonials变量返回到视图中。$testimonials变量是一个对象数组。我有以下观点:

代码语言:javascript
复制
   <table-draggable :testimonials="{{ $testimonials }}"></table-draggable>

我有一个在我的应用程序中正确注册的TableDraggable组件。此组件具有以下代码:

代码语言:javascript
复制
<template>
<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Quote</th>
            <th>Visible</th>
            <th>Order</th>
            <th>Sort</th>
        </tr>
    </thead>

    <draggable v-model="testimonialsNew" draggable=".testimonial" @change="update" handle=".handle">
        <tr v-for="testimonial in testimonialsNew" :key="testimonial.id" class="testimonial">
            <td>
                {{ testimonial.id }}
                <a :href="'testimonials/' + testimonial.id + '/edit'" class="btn btn-primary btn-xs mb">Edit</a>
                <form :action="'testimonials/' + testimonial.id" method="POST">
                    <input type="hidden" name="_token" :value="csrf">
                    <input type="hidden" name="_method" value="delete">

                    <button type="submit" class="btn btn-danger btn-xs">Delete</button>
                </form>

            </td>
            <td>{{ testimonial.name }}</td>
            <td>{{ testimonial.quote }}</td>
            <td>{{ testimonial.visible }}</td>
            <td>{{ testimonial.order }}</td>
            <td><i class="fa fa-arrows my-handle"></i></td>
        </tr>

    </draggable>

    </table>
</template>

<script>
    import draggable from 'vuedraggable'
    export default {
        components: {
            draggable
        },
        props: ['testimonials'],
        data() {
            return {
                testimonialsNew: this.testimonials,
                csrf: document.head.querySelector('meta[name="csrf-token"]').content
            }
        },
        methods: {
            update() {
                this.testimonialsNew.map((testimonial, index) => {
                    testimonial.order = index + 1;
                })
                axios.put('/admin/testimonials/updateAll', {
                    testimonials: this.testimonialsNew
                }).then((response) => {
                    // success message
                })
            }
        },
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

数据正在返回,但没有可拖动的内容。我99%确定错误在这两行中:

代码语言:javascript
复制
        <draggable v-model="testimonialsNew" draggable=".testimonial" @change="update" handle=".handle">
        <tr v-for="testimonial in testimonialsNew" :key="testimonial.id" class="testimonial">

然而,似乎什么都不起作用。

EN

回答 1

Stack Overflow用户

发布于 2020-07-27 04:21:04

您的可拖动类是.handle,但您使用的是my-handle。另外,我建议在draggable元素上使用tag="tbody“来获得有效的html。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63104734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档