zoukankan      html  css  js  c++  java
  • Vue+element UI穿梭框使用

    <template>
      <el-card style="margin: 10px">
        <div class="detailBox">
            <el-transfer v-model="value" :data="peopleNum" :button-texts="['到左边', '到右边']" @change="handleChange"></el-transfer>
            <el-button type="primary" class="btn" @click="submitData">任务分配</el-button>
        </div>
      </el-card>
    </template>
    <script>
      import {
      queryPeopleData,
      submitPeopleData
    } from '@/api/classifyWords'  //请求后台的接口
      export default {
       data() {
          return {
            peopleNum:[],
            value: [],
            leftValue:[],
            rightValue:[],
          }
        },
        created() {
          this.getPeopleData()
        },
        methods: {
          getPeopleData(){
            queryPeopleData().then(res=>{
              let allData = res.data
              allData.forEach(e=>{
                this.peopleNum.push({
                  key:e.id,
                  label:e.name
                })
              })
            })
          },
          handleChange(value,direction,movedKeys){
            if(direction === 'right'){
              movedKeys.forEach(key=>{
                let index = this.leftValue.findIndex(item => item === key)
                this.leftValue.splice(index,1)
              })
              movedKeys.forEach(key =>{
                this.rightValue.push(key)
              })
            }else{
              movedKeys.forEach(key=>{
                let index = this.rightValue.findIndex(item => item === key)
                this.rightValue.splice(index,1)
              })
              movedKeys.forEach(key =>{
                this.leftValue.push(key)
              })
            }
          },
          submitData(){
            if(this.rightValue == null || this.rightValue.length == 0){
              this.$alert("请先选择用户","提示",{
                confirmButtonText:"确定"
              })
            }else{
              submitPeopleData(this.rightValue).then(res=>{
                this.$message({
                  message: '任务分配成功',
                  type: 'success'
                });
              })
            }
          }
        }
      }
    </script>
    <style scoped>
        .infoText {
            font-size: 14px;
            margin-top: 10px;
        }
        .detailBox {
            border: 1px solid #000;
             800px;
            height: 600px;
            margin-left: 30px;
            padding: 30px;
        }
        .btn {
            margin: 30px auto;
            display: block;
        }   
    </style>
  • 相关阅读:
    HTML5 jQuery图片上传前预览
    html5中form表单新增属性以及改良的input标签元素的种类
    PHP邮箱的正则表达式
    PHP手机号码正则表达式
    CSS中设置div垂直居中
    Linux服务器查看内存占用命令
    linux压缩解压文件
    网页是静态还是伪静态?
    帝国cms内容批量替换
    帝国CMS【操作类型】说明详解
  • 原文地址:https://www.cnblogs.com/xiaofang234/p/15427515.html
Copyright © 2011-2022 走看看