vue中拖拽插件之vue-slicksort的使用,踩坑

门户项目中需要进入后台操作门户界面的排版,考虑到使用的方便,于是采用了拖拽插件------vue-slicksort

//  首先npm插件
$ npm install vue-slicksort --save       
//  引入组件
import { SlickList, SlickItem } from 'vue-slicksort'
//  注册组件
components: {
        SlickList,
        SlickItem
},

详细代码如下

<template>
    <div class="edit-plate">
        <SlickList :lockToContainerEdges="true" axis="y" lockAxis="y" v-model="items" class="SortableList"
            @input="getChangeList">
            <div>
                <el-button type="text" @click="handClick(items)" class="el-icon-plus plate-add"
                    style="background-color: #fff;text-align: center;width: 100%;display: inline-block;line-height: 40px;">
                    点击添加</el-button>
            </div>
            <SlickItem v-for="(item, index) in items" class="SortableItem" :index="index" :key="index">
                <h1
                    style="padding: 0;margin: 0;border-bottom: 1px dashed #cccccc;font-size: 18px;padding: 10px;text-align: center;cursor: pointer;background-color: #99999917;">
                    <span>{{ item.name }}</span>
                    <el-button type="text" class="el-icon-edit-outline" @click="handClick(item)" title="编辑"></el-button>
                    <el-button type="text" class="el-icon-delete" @click="handClick(item)" title="删除"></el-button>
                </h1>
                <div class="root">
                    <SlickList :lockToContainerEdges="true" class="list" axis="x" lockAxis="x" v-model="item.itemArr"
                        style="border-bottom:1px solid #eee;display:flex" @input="getChangeLists">
                        <SlickItem class="list-item" v-for="(item, index) in item.itemArr" :index="index" :key="index"
                            style="line-height: 42px;padding: 40px 20px;background-color: #ffffff;border-right:1px solid #eee;text-align:center;box-sizing: border-box;user-select: none;flex-wrap: nowrap;flex: 1;cursor: pointer">
                            <span>{{ item.name }}</span>
                            <el-button type="text" class="el-icon-edit-outline" @click="handClick(item)" title="编辑">
                            </el-button>
                            <el-button type="text" class="el-icon-delete" @click="handClick(item)" title="删除">
                            </el-button>
                        </SlickItem>
                        <span>
                            <el-button type="text" @click="handClick(item.itemArr)" class="el-icon-plus plate-add"
                                style="background-color: #fff;text-align: center;width: 80px;display: inline-block;line-height: 120px;">
                            </el-button>
                        </span>
                    </SlickList>
                </div>
            </SlickItem>
        </SlickList>
    </div>
</template>
<script>
import { SlickList, SlickItem } from 'vue-slicksort'
export default {
    data () {
        return {
            form: {},
            open: false,
            flag: true,
            items: [
                {
                    name: '实验室漫游',
                    itemArr: [{ name: '实验室漫游' }, { name: '全景航拍' }]
                },
                {
                    name: '虚拟仿真教学系统',
                    itemArr: [{ name: '虚拟仿真教学系统' }]
                },
                {
                    name: '公告通知',
                    itemArr: [{ name: '新闻' }, { name: '通知' }]
                },
                {
                    name: '实验教学资源',
                    itemArr: [{ name: '实验视频' }, { name: '实验文档' }, { name: '实验软件' }]
                }
            ]
        }
    },
    components: {
        SlickList,
        SlickItem
    },
    methods: {
        getChangeList (e) {
            window.console.log(e, 'val')
        },
        getChangeLists (e) {
            window.console.log(e, 'vals')
        },
        handClick (e) {
            this.open = !this.open
            this.form = {}
            window.console.log(e, 'vals')
        }
    }
}
</script>
<style lang="less">
.edit-plate {
    .el-button--text {
        padding: 0;
    }
}
</style>
<style lang="scss" scoped>
.edit-plate {
    .list-item {
        float: left;
    }
    .root {
        overflow: hidden;
    }
    .SortableItem {
        box-sizing: border-box;
        visibility: none !important;
        background: #fff;
        &:last-child {
            border: none;
        }
        .root {
            background-color: #f3f3f3;
        }
    }
    .SortableList {
        width: 100%;
        background-color: #f3f3f3;
        border: 1px solid #cccccc;
    }
}
</style>

因为每一次拖拽,dom都是重新渲染,写css没用,只能写成行内样式.此代码是模拟数据的静态文件,可以直接粘贴.效果图如下
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值