Vue.draggable: [Vue warn]: Avoid mutating a prop directly

Created on 29 May 2018  路  3Comments  路  Source: SortableJS/Vue.Draggable

Hi,

I am getting this error message everytime I try to re-order.

[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders

This is npm install in Laravel project and I am using this on one of my Vue Component to show list of categories and re-order them.

My component template

<template>

    <div class="box">

        <table class="table is-fullwidth is-hoverable">

            <thead>

                <tr>
                    <th>Category (Drag to re-order)</th>
                </tr>

            </thead>

            <tbody>
                <draggable v-model="categories">
                    <tr v-for="(category,index) in categories" :key="category.catslug">
                        <td>
                            <span class="tag is-dark">{{ index+1 }}</span>
                            &nbsp;
                            {{ category.catname }}
                        </td>
                    </tr>
                </draggable>
            </tbody>

        </table>

        <button class="button is-primary" @click="showCats">Update</button>

    </div>

</template>



<script>

    import draggable from 'vuedraggable';

    export default {

        components: {
            draggable,
        },

        props: ['categories'],


        methods: {

            showCats: function() {
                console.log(this.categories);
            }

        },

    }

</script>

categories is query result from php.

Using Vuejs 2

Any suggestion?

Thanks!

Most helpful comment

Use :list instead of v-model

All 3 comments

Use :list instead of v-model

Tried :list. Now it doesn't reorder. Dragged item goes back to old place.

Create a jsfidle

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kuohao-wu picture Kuohao-wu  路  3Comments

Nrqz picture Nrqz  路  3Comments

Kgwkgwkgw picture Kgwkgwkgw  路  3Comments

iou90 picture iou90  路  3Comments

mathlet0x picture mathlet0x  路  4Comments