Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue可拖动-拖放后动态更改组件_Vue.js_Vuedraggable - Fatal编程技术网

Vue.js Vue可拖动-拖放后动态更改组件

Vue.js Vue可拖动-拖放后动态更改组件,vue.js,vuedraggable,Vue.js,Vuedraggable,我有两个单独的Dragarea,当我将组件从一个区域拖动到另一个区域时,如何根据组件拖动到的区域动态更改组件的状态 目前,我正在从序列化程序呈现状态,但我希望在拖放后动态更改它 <draggable class="dragArea published" :options="{ group: { name: 'g1', put: 'g1'}, animation: 120 }" @end="onEnd"> <div v-for="lesson in

我有两个单独的Dragarea,当我将组件从一个区域拖动到另一个区域时,如何根据组件拖动到的区域动态更改组件的状态

目前,我正在从序列化程序呈现状态,但我希望在拖放后动态更改它

<draggable
  class="dragArea published"
  :options="{ group: { name: 'g1', put: 'g1'}, animation: 120 }"
  @end="onEnd">
    <div
      v-for="lesson in classroomLessonsPublished"
      :class="`lesson-card ${lesson.id}`"
      data-status="published">   
        <div> 
          {{ lesson.status }}
        </div>
    </div>
</draggable>

<draggable
  class="dragArea unpublished"
  :options="{ group: { name: 'g1', put: 'g1'}, animation: 120 }"
  @end="onEnd">
    <div
      v-for="lesson in classroomLessonsUnpublished"
      :class="`lesson-card ${lesson.id}`"
      data-status="unpublished">   
        <div> 
          {{ lesson.status }}
        </div>
   </div>
</draggable>

{{lesson.status}
{{lesson.status}

可拖动组件发出一个事件:

当列表属性不为空且 由于拖放操作,相应的数组被更改

传递给事件的参数有一个名为
added
的属性,该属性包含添加到数组中的元素的信息

{
  newIndex: number, // the index of the added element
  element: T // the added element,
}

示例:将图元从已发布组拖放到未发布组

模板:

<draggable
  class="dragArea unpublished"
  :options="{ group: { name: 'g1', put: 'g1'}, animation: 120 }"
  @change="onUnpublishedChange"
  @end="onEnd"
>
  <!-- ... -->
</draggable>

您的组具有相同的名称,您可能应该将其更改为:

出版:

:options="{ group: { name: 'published', put: 'unpublished'}, animation: 120 }"
未出版:

:options="{ group: { name: 'unpublished', put: 'published'}, animation: 120 }"

您可以使用“如何识别组件已放置到的区域”,以便动态组件显示正确的状态?
:options="{ group: { name: 'unpublished', put: 'published'}, animation: 120 }"