vue实现 input模糊搜索 和简单的穿梭框

<template>
  <div class="main">
    <div class="box1">
      <el-input v-model="input" placeholder="请输入内容" size="mini"
       @change="changeValue" @input="inputValue"></el-input>
      <el-checkbox-group
    v-model="checkedCities"
    @change="changeEvent"
    >
    <el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox>
  </el-checkbox-group>
    </div>
    <div class="box2">
        <div>已选择数据</div>
      <ul>
        <li v-for="(item,index) in list" :key="index">{{item}}
        <div class="del" @click="delDate(index)">x</div></li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      input: '',
      checkedCities: [],
      cities: ['上海a', '北京b', '广州c'],
      list: [],
      newCities: []
    }
  },
  created () {
  // 需要把初始的数据拷贝一份 实现数据的独一性
    this.newCities = JSON.parse(JSON.stringify(this.cities))
  },
  methods: {
    changeValue () {
      console.log(this.input)
    },
    inputValue () {
      const _search = this.input.toLowerCase() // 用于把字符串转为小写
      const newListData = [] // 用于存放搜索出来数据的新数组
      this.newCities.filter(item => {
        if (item.indexOf(_search) !== -1) {
          newListData.push(item)
        }
      })
      this.cities = newListData
      console.log('newCities', this.newCities)
    },
    changeEvent (value) {
      this.list = value
    },
    delDate (index) {
      this.list.splice(index, 1)
    }
  }
}
</script>
<style lang= 'scss' >
.main{
  border: 1px solid #f99;
  margin-top: 80px;
  display: flex;
  justify-content: space-between;
  width: 600px;
  height: 300px;
  .box1{
    border: 1px solid #000;
    width: 45%;
  }
  .box2{
    width: 45%;
    border: 1px solid #000;
    li{
      height: 30px;
      padding:5px 10px;
      margin-bottom: 2px;
      background: #f99;
      .del{
        border: 1px solid #fff;
        float: right;
        font-size: 20px;
      }
    }
  }
}
</style>
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值