1

我似乎无法让可拖动组件正常工作。

我得到的错误是:

Error in mounted hook: "TypeError: external_commonjs_sortablejs_commonjs2_sortablejs_amd_sortablejs_root_Sortable_default.a is not a constructor"

我曾尝试阅读此内容,但信息有限: https ://github.com/SortableJS/Vue.Draggable/issues/738

我在下面发布了一个示例代码,希望得到一个指针。

main.js

import Vue from 'vue'
import App from './App.vue'

new Vue({
    el: '#app',
    render: h => h(App)
})

应用程序.vue

<template>
    <div class="container">
        <listComponent></listComponent>
    </div>
</template>

<script>
    import Draggable from './components/Draggable/Draggable.vue';

    export default {
        components: {
            listComponent: Draggable
        }
    }
</script>

<style>

</style>

可拖动的.vue

<template>
  <div>
    <h2 class="title">Draggable example</h2>
    <draggable
      v-model="exampleList"
      class="bigger-area"
    >
      <transition-group name="list-complete">
        <div
          v-for="text in exampleList" :key="text"
          class="drag-item flex flex-justify-betweeen"
          @dragend="log('a')"
          @start="drag=true"
        >{{ text }}</div>
      </transition-group>
    </draggable>
  </div>
</template>

<script>
import draggable from "vuedraggable";

export default {
  name: "Drag",
  data() {
    return {
      exampleList: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
    };
  },
  components: {
    draggable
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.title {
  margin-bottom: 2em;
}
.bigger-area > span {
  min-height: 90vh;
  display: block;
}
.drag-item {
  padding: 15px 10px;
  background-color: whitesmoke;
  min-width: 30vw;
  max-width: 90vw;
  margin: 0 auto 10px;
  cursor: -moz-grab;
  cursor: -webkit-grab;
  cursor: grab;
  transition: transform 0.25s cubic-bezier(0.02, 1.01, 0.94, 1.01);
  will-change: transform;
}
.list-complete-enter,
.list-complete-leave-active {
  opacity: 0;
}
</style>
4

0 回答 0