Vue.draggable: Use with Nuxt?

Created on 30 Dec 2018  路  5Comments  路  Source: SortableJS/Vue.Draggable

Created a plugin:

vuedraggable.js
import Vue from 'vue'
import draggable from 'vuedraggable'

Vue.use(draggable)

imported in nuxt.config.js

    plugins: [
        { src: '~plugins/vuedraggable.js', ssr: false }
    ]

and try to use it like:

<template lang="pug">
.container
    div
        h2 Draggable Wrapper
        draggable(v-model='exampleList')
            div(v-for='text in exampleList', :key='text')
</template>
<script>
import draggable from 'vuedraggable'
export default {
    components: {
        draggable
    },
    layout: 'empty',
    data() {
        return {
            exampleList: [
                'Item 1',
                'Item 2',
                'Item 3',
                'Item 4',
                'Item 5'
            ]
        }
    },
}

What am I missing here?

question

Most helpful comment

Hi,
replace your plugin code with this:

import Draggable from 'vuedraggable';
import Vue from 'vue';
Vue.component('draggable', Draggable);

And remove import draggable from 'vuedraggable' from your .vue file.

All 5 comments

Hi,
replace your plugin code with this:

import Draggable from 'vuedraggable';
import Vue from 'vue';
Vue.component('draggable', Draggable);

And remove import draggable from 'vuedraggable' from your .vue file.

As stated by @PlainBane , Vue.use(draggable) won't work use Vue.component('draggable', Draggable); instead

When I introduce the following code into vueDraggable. Js, I still cannot globally introduce vueDraggable

import Draggable from 'vuedraggable'
import Vue from 'vue'
Vue.component('draggable', Draggable)

I wonder if the ssr: false is really a good idea?... I needed to use this:

 // using index.js in /plugins/draggable
 plugins: [
        { src: '@/plugins/draggable'} 
    ]

To avoid getting:
The client-side rendered virtual DOM tree is not matching server-rendered

Thanks! this help me save my time a lot =)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kuohao-wu picture Kuohao-wu  路  3Comments

rootman picture rootman  路  3Comments

AnnaStuehlmeyer picture AnnaStuehlmeyer  路  3Comments

mathlet0x picture mathlet0x  路  4Comments

AlexandreBonneau picture AlexandreBonneau  路  3Comments