vue實現(xiàn)穿梭框

頁面展示

在這里插入圖片描述

html

  <body>
    <div id="my">
      <div class="container-fluid">
        <div class="row">
          <!--左側(cè)-->
          <div class="col-xs-5 col-sm-5">
            <div class="panel panel-success">
              <!--標(biāo)題-->
              <div class="panel-heading clearfix">
                <span class="pull-right"></span>
              </div>
              <!--內(nèi)容-->
              <div class="panel-body panel-height">
                <ul class="list-unstyled">
                  <li>
                    <div class="checkbox">
                      <label>
                        <input type="checkbox" />
                      </label>
                    </div>
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <!--中間-->
          <div class="col-xs-2 col-sm-2 text-center">
            <div>
              <button type="button" class="btn btn-primary anniu">>></button>
            </div>
            <br />
            <div>
              <button type="button" class="btn btn-primary anniu"><<</button>
            </div>
          </div>
          <!--右側(cè)-->
          <div class="col-xs-5 col-sm-5">
            <div class="panel panel-info">
              <!--標(biāo)題-->
              <div class="panel-heading clearfix">
                <span class="pull-right"></span>
              </div>
              <!--內(nèi)容-->
              <div class="panel-body panel-height">
                <ul class="list-unstyled">
                  <li>
                    <div class="checkbox">
                      <label>
                        <input type="checkbox" />
                      </label>
                    </div>
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>

javascript

window.onload = function () {
  new Vue({
    el: "#my",
    data: {
      leftData:[
        {id:1,name:'數(shù)據(jù)1',check:true},
        {id:2,name:'數(shù)據(jù)2',check:false},
        {id:3,name:'數(shù)據(jù)3',check:false},
        {id:4,name:'數(shù)據(jù)4',check:false},
        {id:5,name:'數(shù)據(jù)5',check:false},
        {id:6,name:'數(shù)據(jù)6',check:false},
        {id:7,name:'數(shù)據(jù)7',check:false},
        {id:8,name:'數(shù)據(jù)8',check:false},
        {id:9,name:'數(shù)據(jù)9',check:false},
      ],
      rightData:[]//右側(cè)數(shù)據(jù)
    },
    computed: {
      num() {
        return function(data,state) {
          return this.commonEvt(data,state).length
        }
      }
    },
    methods: {
      // 把左邊的數(shù)據(jù)添加到右邊
      toRight() {
        var arr = this.commonEvt(this.leftData,true);
        if(arr.length) {
          this.rightData = [...this.rightData,...arr]; 
          this.leftData = this.commonEvt(this.leftData,false); // 左邊顯示的數(shù)據(jù)
        } else {
          alert("請勾選數(shù)據(jù)")
        }
      },
      toLeft() {
        var arr = this.commonEvt(this.rightData,true)
        if(arr.length) {
          this.leftData = [...this.leftData,...arr]; // 左邊顯示添加的數(shù)據(jù)
          this.rightData = this.commonEvt(this.rightData,false); // 右邊顯示的數(shù)據(jù)
        } else {
          alert("請勾選數(shù)據(jù)")
        }
      },
      //  公共篩選方法
      commonEvt(data,state) {
        return data.filter(item => item.check == state)
      }
    },
    mounted() {

    }
  })
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 16宿命:用概率思維提高你的勝算 以前的我是風(fēng)險厭惡者,不喜歡去冒險,但是人生放棄了冒險,也就放棄了無數(shù)的可能。 ...
    yichen大刀閱讀 7,974評論 0 4
  • 公元:2019年11月28日19時42分農(nóng)歷:二零一九年 十一月 初三日 戌時干支:己亥乙亥己巳甲戌當(dāng)月節(jié)氣:立冬...
    石放閱讀 7,493評論 0 2
  • 年紀(jì)越大,人的反應(yīng)就越遲鈍,腦子就越不好使,計劃稍有變化,就容易手忙腳亂,亂了方寸。 “玩壞了”也是如此,不但會亂...
    玩壞了閱讀 2,351評論 2 1
  • 感動 我在你的眼里的樣子,就是你的樣子。 相互內(nèi)化 沒有絕對的善惡 有因必有果 當(dāng)你以自己的價值觀幸福感去要求其他...
    周粥粥叭閱讀 1,741評論 1 5
  • 昨天考過了阿里規(guī)范,心里舒坦了好多,敲代碼也猶如神助。早早完成工作回家嘍
    常亞星閱讀 3,267評論 0 1

友情鏈接更多精彩內(nèi)容