vue实现数组上移下移置顶置底

admin4年前vue579

swapItems: function(arr, index1, index2, direction) {
               
if(direction == 'up'){
                    //置顶
                    arr.unshift(arr[index1]);
                    arr.splice(index1+1, 1);
                    return arr;
                }
                if(direction == 'down'){
                    //置底
                    arr.push(arr[index1]);
                    arr.splice(index1,1);
                    return arr;
                }
                arr[index1] = arr.splice(index2, 1, arr[index1])[0];
                return arr;
            },

,

up(k) {

                if(k == 0) {
                    layer.msg('已经是最顶部了');
                    return;
                }
                this.datas = this.swapItems(this.datas, k, k - 1);
                var datas = this.datas;
                datas.forEach(function(e, k) {
                    datas[k].sort_order = k;
                })
            },
            down(k) {
                var index = this.datas.length - 1;
                if(k == index) {
                    layer.msg('已经是最底部了');
                    return;
                }
                this.datas = this.swapItems(this.datas, k, k + 1);
                var datas = this.datas;
                datas.forEach(function(e, k) {
                    datas[k].sort_order = k;
                })
            },


相关文章

vue : 无法加载文件 C:\Users\Lenovo\AppData\Roaming\npm\vue.ps1,因为在此系统上禁止运行脚本

右键开始菜单管路员运行 power shellset-ExecutionPolicy RemoteSigned 选择Y或A即可...

el-date-picker禁用当天前的日期

<el-date-picker type="date" placeholder="请选择最早提货日期" v-model="addForm.pic...

vue滚动加载列表

new Vue({    el: '#app',    data: {  &n...

vue上传片段代码

uploadFile: function(e) {           &nb...

在VUE中使用swiper

npm i swiper<template>   <swiper     :slides-per-...

Vue v3组件命名不支持驼峰命令

<script>        const testItem = {           ...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。