bash
复制代码
<el-button @click="addfirst()" type="text" class='el-icon-circle-plus-outline' ></el-button>
<draggable
v-model="myArray"
group="people"
@change="change"
@start="start"
@end="end"
>
<div class="item" v-for="(first, index) in myArray" :key="index">
<!-- {{ index }} -->
<el-input style='width:20%' clearable v-model.trim="first.name" placeholder="请输入"></el-input>
<el-button type="text" class="el-icon-delete" style='width:4%' @click.prevent="removefirst(first)"></el-button>
</div>
</draggable>
<el-button class="searchBtn" @click="tijiao()" type="primary">提交</el-button>
bash
复制代码
data() {
return {
myArray: [
{
name:''
},
],
}
}
bash
复制代码
// 删除1
removefirst(item) {
var index = this.myArray.indexOf(item)
this.myArray.splice(index, 1)
},
addfirst(){
this.myArray.push({
name:'',
});
},
tijiao(){
console.log(this.myArray)
},
// 监听拖拽
change(event) {
// console.log("change");
// console.log(event);
// console.log(this.myArray);
},
// 开始拖拽
start(event) {
// console.log("start");
// console.log(event);
// console.log(this.myArray);
},
// 结束拖拽
end(event) {
// console.log("end");
// // event.item 拖拽的本身
// // event.to 拖拽的目标列表
// // event.from 拖拽之前的列表
// // event.oldIndex 拖拽前的位置
// // event.newIndex 拖拽后的位置
// console.log(event);
// console.log(this.myArray);
},