Vue 中的vue-slicksort拖拽效果组件

一 : vue-slicksort 一款功能强大的可拖拽的vue.js组件。拥有丝滑般拖拽动画效果,支持水平/垂直/网格拖拽排序。还可以自动滚动、锁定坐标系,并支持触摸。使用如下:

使用npm

  $ npm install vue-slicksort --save

使用yarn:

  $ yarn add vue-slicksort

 

二 :项目中的使用  参考1

<template>
    <div class="box-sort">
        <p>刷新次数: {{ count }}</p>
        <div class="slick-list_wrapper">
            <slick-list
                v-model="goods_list"
                lock-axis="y"
                helper-class="slick-item"
                :use-drag-handle="true"
                append-to=".slick-list_wrapper"
            >
                <template v-for="(item, index) in goods_list">
                    <slick-item :key="index" class="slick-item" :index="index">
                        <i v-handle class="btn">拖到</i>
                        <div class="item">
                            {{ item.name }}
                        </div>
                    </slick-item>
                </template>
            </slick-list>
            <div class="add-one" @click="addHandle()">添加</div>
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { PullRefresh } from "vant";
    1 引入
import { SlickList, SlickItem, HandleDirective } from "vue-slicksort";
@Component({
    name: "VantLearn",
    2 组件
    components: {
        SlickList,
        SlickItem
    },
    3  定义的方法
    directives: {
        handle: HandleDirective
    }
})
export default class VantLearn extends Vue {

    count = 0;
    goods_list: any[] = [
        {
            name: "小李",
            age: 22,
            sex: "女的"
        },
        {
            name: "小王",
            age: 20,
            sex: "女的"
        },
        {
            name: "小张",
            age: 23,
            sex: "女的"
        },
        {
            name: "小刘",
            age: 33,
            sex: "男的"
        }
    ];
     
    // 自定义添加数据方法
    addHandle(): void {
        this.goods_list.push({
            name: this.count + 18 + "岁妹子",
            age: "18" + this.count++,
            sex: "妹子"
        });
    }

    // 可调接口 请求数据选择 
   async created(): Promise<any> {
        const data = await getCollectList({ size: 5, page: 1, is_buy: 0 });
        this.goods_list = data.rows;
        console.log(121212, data);
    }
}
</script>
<style lang="scss" scoped>
.box-sort {
    width: 100%;
    height: 100%;
}
.slick-list_wrapper {
    width: 100%;
    text-align: center;
    font-size: 24px;
    // .slick-list {
    //     // position: relative;
    //     // z-index: 2;
    //     // height: 100%;
    //     width: 100%;
    //     border-radius: 12px;
    //     background-color: #ffffff;
    // overflow: hidden;
    .slick-item {
        display: flex;
        // flex-wrap: wrap;
        // justify-content: space-between;
        width: 100%;
        border: rgb(48, 16, 4) 1px solid;
        margin: 2px 0;
        font-size: 30px;
        .btn {
            width: 100px;
            height: 50px;
            font-size: 20px;
            border: solid 1px chocolate;
            color: red;
        }
        .item {
            height: 100px;
            width: 100%;
            // flex: 0 0 60px;
            font-size: 24px;
        }
    }
    // }
    .add-one {
        width: 100%;
        text-align: center;
        font-size: 30px;
        color: darkgoldenrod;
    }
}
</style>

三 1 参数配置

名称类型默认值说明
valueArray-列表内容
axisStringy

列表数据可以按横向拖动,纵向拖动还是网格拖动。

用x,y,xy表示

lockAxisString-用于排序时在坐标系中锁定元素的移动
helperCkassString-helper的自定义样式
tansitionDurationNumber300元素移动动画的持续时间
pressDelayNumber 0

如果需要当元素被按下一段时间在允许拖动,

设置此属性

pressThresholdNumber5移动允许被忽略的阀值,单位像素
distanceNumber0

如果需要在拖拽出一定的距离之后才被识别为正

在拖动的元素,可以设置此属性

useDragHandleBoolean     false如果使用HandleDirective, 设置为true
useWindowAsScrollContainerBooleanfalse是否设置window为可滚动的容器
hideSortableGhostBooleantrue

是否自动隐藏Ghost元素

lockToContainerEdgesBooleanfalse是否对正在拖动的元素锁定容器边缘
lockOffsetString50%对正在拖动的元素锁定容器边缘的偏移量
shouldCancelStartFunction-在拖动开始前这个方法将被调用
getHelperDimensionsFunction-可选方法({ node, index, collection}), 应该返回 SortableHelper 的计算维度。

 2. 事件

名称参数说明
sortStartevent,node, index,collection当拖拽开始触发
sortMoveevent当拖拽时鼠标移动时触发
sortEndevent, newIndex,oldIndex, collection当拖拽结束时触发
inputnewList当拖拽结束后产生新的列表结束后触发。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值