vueJs2.0穿梭框实现

首先简介一下穿梭狂的含义:点击左边的商品就会进入右边的已选商品列表,同时也可以点击右边的商品删除已经选择的商品;

主要代码如下:

<template>
  <div class="hello">
    <div class="one">
      <p v-for="msg in message" @click="clickP(msg)">{{msg.name}}</p>
    </div>
    <div class="two">
      <p v-for="data in newdatas" @click="deleteP(data)">{{data.name}}</p>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        msg: '哈哈',
        hh: '呵呵',
        message: [
          {id: 1, name: '第一个'},
          {id: 2, name: '第二个'},
        ],
        datas: [],
        newdatas: []
      }
    },
    mounted: function () {

    },
    methods: {
      clickP: function (msg) {
        this.datas.push(msg)
        this.newdatas = this.unique(this.datas)
      },
      deleteP: function (data) {
        for( let i=0;i<this.newdatas.length;i++){
          console.log('输出');
          console.log(this.newdatas[i]);
          if(this.newdatas[i].id==data.id){
            this.newdatas.splice(i,1);
            this.datas.splice(0,this.datas.length);
          }
        }
      },
      // 除重
      unique: function (a) {
        let res = []
        for (let i = 0, len = a.length; i < len; i++) {
          let item = a[i];
          (res.indexOf(item) === -1) && res.push(item)
        }
        return res
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .hello {
    display: flex;
    justify-content: center;
  }

  .one, .two {
    width: 300px;
    height: 400px;
    outline: 1px solid red;
  }

</style>

VueJS2.0  QQ交流群:424882195,欢迎大家加入互相学习交流!

我个人微信公众号:欢迎大家关注下:
名称:U世界的V梦想
二维码:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值