v
-
for
=
"resultlists in resultlists"
:
key
=
"resultlists.id"
class
=
"list-complete-item"
<
div
class
=
"list-complete-item-handle"
>
{
{
resultlists
.
name
}
}
<
/
div
>
<
/
div
>
<
/
draggable
>
<
/
div
>
<
div
class
=
"optionsContent"
>
<
draggable
:
list
=
"targetLists"
:
options
=
"
{
group
:
{
name
:
optionsName
,
pull
:
'clone'
}
,
sort
:
false
,
filter
=
".undraggable"
@end
=
"optionEnd"
class
=
"dragArea"
v
-
for
=
"targetList in targetLists"
:
key
=
"targetList.id"
:
class
=
"{ undraggable: targetList.flag }"
class
=
"list-complete-item"
<
div
class
=
"list-complete-item-handle2"
>
{
{
targetList
.
name
}
}
<
/
div
>
<
/
div
>
<
/
draggable
>
<
/
div
>
<
/
div
>
<
/
div
>
<
/
template
>
<
script
>
import
draggable
from
"vuedraggable"
;
export
default
{
name
:
"DndList"
,
components
:
{
draggable
}
,
watch
:
{
}
,
data
(
)
{
return
{
optionsName
:
"article"
,
disabled
:
false
,
resultlists
:
[
]
,
targetLists
:
[
{
id
:
1
,
name
:
"平板支撑"
}
,
{
id
:
2
,
name
:
"俄挺"
}
,
{
id
:
3
,
name
:
"空中自行车"
}
,
{
id
:
4
,
name
:
"波比"
}
,
{
id
:
5
,
name
:
"两头起摸脚"
}
,
{
id
:
6
,
name
:
"窄距俯卧撑"
}
,
{
id
:
7
,
name
:
"宽距俯卧撑"
}
,
{
id
:
8
,
name
:
"钻石俯卧撑"
}
,
{
id
:
9
,
name
:
"空中击掌俯卧称"
}
,
{
id
:
10
,
name
:
"深蹲提膝跳"
}
,
computed
:
{
}
,
methods
:
{
optionEnd
(
ev
)
{
if
(
ev
.
to
.
className
===
"targetCard"
)
{
this
.
$set
(
this
.
targetLists
[
ev
.
oldIndex
]
,
"flag"
,
true
)
;
targetStart
(
)
{
this
.
optionsName
=
"1111"
;
targetEnd
(
)
{
this
.
optionsName
=
"article"
;
<
/
script
>
<
style lang
=
"less"
scoped
>
.
container
{
width
:
100
%
;
height
:
100
%
;
background
-
color
:
rgba
(
5
,
35
,
56
,
0.6
)
;
display
:
flex
;
align
-
items
:
center
;
justify
-
content
:
center
;
.
content
{
width
:
1200
px
;
height
:
600
px
;
background
-
color
:
#
052338
;
display
:
flex
;
.
targetContent
{
width
:
100
%
;
height
:
100
%
;
.
optionsContent
{
width
:
100
%
;
height
:
100
%
;
border
-
left
:
2
px solid #
4
ab7bd
;
.
list
-
complete
-
item
{
display
:
inline
-
block
;
font
-
size
:
16
px
;
font
-
weight
:
400
;
color
:
#ffffff
;
padding
:
10
px
18
px
;
margin
:
10
px
8
px
0
;
background
:
rgba
(
237
,
245
,
255
,
0.1
)
;
border
:
1
px solid #bfcbd9
;
border
-
radius
:
0.18
rem
;
cursor
:
pointer
;
transition
:
all
1
s
;
.
list
-
complete
-
item
.
sortable
-
chosen
{
background
:
#
4
ab7bd
;
.
list
-
complete
-
item
.
sortable
-
ghost
{
background
:
#
30
b08f
;
.
undraggable
{
background
-
color
:
rgb
(
143
,
233
,
233
)
;
.
list
-
complete
-
enter
,
.
list
-
complete
-
leave
-
active
{
opacity
:
0
;
<
/
style
>
@start = "startChange"
@end= "endChange"
:options="{
group: { name: optionsName, pull: 'clone' },
sort: false,
disabled: false,
animation: 150,
filter: ".ignore-elements",
draggable: ".item",
ghostClass: "sortable-ghost",
chosenClass: "sortable-chosen",
dragClass: "sortable-drag",
选项区域和目标区域的元素样式不一致
选项区域和目标区域的名字不一致,会导致拖动失败
插件版本问题,:options="{}" 的写法已经被弃用,直接使用 v-bind 写法,具体参照介绍
项目需求简单实现一个vue拖拽小案例,右侧选项区拖拽到左侧目标区域,拖动成功的不能再次拖动,并改变颜色。安装 vuedraggable 插件cnpm i -S vuedraggable页面直接引用import draggable from “vuedraggable”;…components: { draggable },源码参考<template> <div class="container"> <div class="conte.