欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue3.0实现穿梭框单点

程序员文章站 2024-01-02 21:24:40
...

vue3.0实现穿梭框单点

*{margin:0; padding:0;}
        li{list-style: none;}
        a{text-decoration: none; color: #333;}
        button{border:none;}
        input{outline:none;}
        textarea{resize:none;}
        em,i{font-style: normal;}
        .wrap{
            width: 1000px;
            margin: 0 auto;
            border: 1px solid red;
        }
        .wrap .header{
            width: 100%;
            height: 80px;
            line-height: 80px;
            border-bottom: 2px solid #ccc;
        }
        .wrap .content{
            width: 100%;
            display: flex;
            flex-direction: row;
        }
        .wrap .content .content_left ,.wrap .content .content_right{
            width:500px;
            text-align: center;
            line-height: 60px;
            border-bottom: 1px solid #333;
            height: 500px;
        }
        .wrap .content .content_left{
            border-right: 1px solid #333;
            overflow-y: scroll;
        }
        .wrap .content .content_left_main li{
            height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .wrap .content .content_left_main li div{
            width: 150px;
            height: 60px;
            background: #1B999A;
            color: #fff;
            cursor: pointer;
        }
        .wrap .content .content_right_main li{
            height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .wrap .content .content_right_main li div{
            width: 150px;
            height: 60px;
            background: #1B999A;
            color: #fff;
            cursor: pointer;
        }
        .wrap .footer{
            width: 100%;
            height: 100px;
            line-height: 100px;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }
        .wrap .footer button{
            width: 150px;
            height: 60px;
            background: #1B999A;
            color: #fff;
            font-size: 16px;
        }
<div class="wrap">
        <div class="header">
            <h2>暂停原因选择</h2>
        </div>
        <div class="content">
            <div class="content_left" >
                <p>待选择</p>
                <ul class="content_left_main" v-for="(item,index) in content_left_main" :key="index" >
                    <li class="clml" >
                        <div @click = 'change(index)'>{{item.message}}</div>
                    </li>
                </ul>
            </div>
            <div class="content_right" >
                <p>以选择</p>
                <ul class="content_right_main" v-for="(item,index) in obj.arr" :key="index">
                    <li class="clml"  >
                        <div @click = 'changetwo(index)'>{{item.message}}</div>
                    </li>
                </ul>
            </div>
        </div>
        <div class="footer">
            <button>保存</button>
            <button>返回</button>
        </div>
    </div>
<script>
import { reactive, watch } from 'vue'
export default {
    setup(){
        const content_left_main=reactive([
            {   
                id:1,
                message:'设备保养'
            },
            {   
                id:2,
                message:'物料等待'
            },
            {   
                id:3,
                message:'工装维护'
            },
            {   
                id:4,
                message:'设备保养'
            },
            {   
                id:5,
                message:'设备保养'
            },
        ])

        const obj = reactive({
            arr:[]
        })
        const content_right_main=reactive([
            {
                id:1,
                message:''
            }
        ])

        const change = (i)=>{
                // console.log(obj.arr.length)
            if(!obj.arr.length>=1){
                // console.log(obj.arr.length)
                // console.log(111)
                obj.arr.push(content_left_main[i])
                content_left_main.splice(i,1)
                console.log(obj.arr)
            }
            
        }
        // watch(obj.arr,(newValue)=>{
        //     if(newValue.length>1){
        //         obj.arr.splice(0,1);
        //     }
        // })
        const changetwo = (i)=>{
            content_left_main.push(obj.arr[i])
            obj.arr.splice(0,1);
        }
        return {
            //reactive
            content_left_main,content_right_main,obj,
            //methods
            change,changetwo
        }
    }
}
</script>

上一篇:

下一篇: