使用Vue实现简易的车牌输入键盘

 更新时间:2023年11月28日 11:08:29   作者:大阳光男孩  
这篇文章主要为大家详细介绍了如何使用Vue实现简易的车牌输入键盘效果,文中的示例代码讲解详细,具有一定的学习价值,感兴趣的小伙伴可以了解下

效果图如下:

代码如下:

<template>
  <div>
    <div class="carNoBoxInput">
      <div style="padding: 6px;border: 2px solid #fff;border-radius: 6px;margin: 6px 3px 6px 6px;">
        <input class="inputBox" :value="licensePlateUnit[0]" @click="licensePlateDoor = true"/>
        <input class="inputBox" :value="licensePlateUnit[1]" @click="licensePlateDoor = true"/>
        <span class="dot"></span>
        <input class="inputBox" :value="licensePlateUnit[2]" @click="licensePlateDoor = true"/>
        <input class="inputBox" :value="licensePlateUnit[3]" @click="licensePlateDoor = true"/>
        <input class="inputBox" :value="licensePlateUnit[4]" @click="licensePlateDoor = true"/>
        <input class="inputBox" :value="licensePlateUnit[5]" @click="licensePlateDoor = true"/>
        <input class="inputBox" :value="licensePlateUnit[6]" @click="licensePlateDoor = true"/>
        <input v-if="7 === licensePlateUnit.length - 1" class="inputBox" :class="7 === licensePlateUnit.length - 1 ? 'inputBoxActive' : 'inputBox'" :value="licensePlateUnit[7]"/>
        <img v-if="7 !== licensePlateUnit.length - 1" src="../assets/newEnergy.png" style="height: 36px;width: 36px;"  alt="新能源"/>
      </div>
    </div>
    <div v-if="licensePlateDoor">
      <div v-if="licensePlateUnit.length < 1" class="carNoBox">
        <span class="carNo" v-for="item in columns" :key="item" @click="pickOn(item)">
          {{item}}
        </span>
        <span class="delBt" @click="delCarNo">X</span>
      </div>
      <div v-if="licensePlateUnit.length >= 1" class="carNoBox">
      <span class="carNo" v-for="item in numberColumns" :key="item" @click="pickOn(item)">
        {{item}}
      </span>
        <div style="display: flex;align-items: center">
          <span class="delBt" @click="delCarNo">X</span>
          <span class="delBt" style="margin-left: 6px;width: 42px" @click="confirm">确认</span>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
 
 
 
export default {
  data() {
    return {
      licensePlateDoor: false,
      activeIndex: 0,
      licensePlateUnit: [],
      columns: [//省缩写选择
        '京', '沪', '鄂', '湘', '川', '渝', '粤', '闽', '晋', '黑',
 
        '津', '浙', '豫', '赣', '贵', '青', '琼', '宁', '吉', '蒙',
 
        '冀', '苏', '皖', '桂', '云', '陕', '甘', '藏', '新', '辽',
        '鲁'],
      numberColumns: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0','Q', 'W', 'E',
        'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z',
        'X', 'C', 'V', 'B', 'N', 'M', '港','澳','学','领','警'
      ],
    }
  },
  methods: {
    pickOn(value) {
      this.licensePlateDoor = true;
      if (this.licensePlateUnit.length <= 7) {
        this.licensePlateUnit.push(value)
      }
    },
    delCarNo() {
      this.licensePlateUnit.pop();
    },
    confirm() {
      if(this.licensePlateUnit.length >= 7) {
        console.log("车牌是:"+this.licensePlateUnit.join(''));
        this.licensePlateDoor = false;
      }
    },
  }
}
</script>
 
 
<style scoped>
  .carNo {
    border-radius: 6px;
    background: #fff;
    font-weight: bold;
    font-size: 20px;
    height: 28px;
    width:28px;
    margin: 6px;
    padding: 12px;
    cursor: pointer;
  }
  .inputBox {
    color: white;
    height: 30px;
    line-height: 30px;
    width: 30px;
    font-size: 28px;
    text-align: center;
    background-color: transparent;
    border: none;
    outline: none;
    caret-color: rgba(0, 0, 0, 0)
  }
  input:focus {
    border-bottom: 3px solid #fff;
    transition: all 0.5s;
  }
  .dot {
    margin-bottom: 6px;
    background-color: #fff;
    height: 6px;
    width: 6px;
    border-radius: 50%;
    display: inline-block
  }
  .delBt {
    background: #ACB3BB;
    border-radius: 6px;
    display: inline-block;
    font-weight: bold;
    font-size: 20px;
    height: 28px;
    width:28px;
    margin: 6px;
    padding: 12px;
    cursor: pointer;
  }
  .carNoBoxInput {
    display: flex;
    width: 310px;
    align-items: center;
    //height: 80px;
    border-radius: 8px;
    margin: 12px 0;
    background: #2D66D8;
  }
  .carNoBox {
    background: #D0D5D9;
    position: relative;
    width: 600px;
    border-radius: 6px;
    display: flex;
    flex-wrap: wrap;
    justify-items: center;
    align-items: center
  }
</style>

到此这篇关于使用Vue实现简易的车牌输入键盘的文章就介绍到这了,更多相关Vue车牌输入键盘内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Vue简单实现原理详解

    Vue简单实现原理详解

    这篇文章主要介绍了Vue简单实现原理,结合实例形式详细分析了Vue实现原理与操作注意事项,需要的朋友可以参考下
    2020-05-05
  • element-ui循环显示radio控件信息的方法

    element-ui循环显示radio控件信息的方法

    今天小编就为大家分享一篇element-ui循环显示radio控件信息的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-08-08
  • vue+axios实现图片上传识别人脸的示例代码

    vue+axios实现图片上传识别人脸的示例代码

    本文主要介绍了vue+axios实现图片上传识别人脸,这里采用的是vant的文件上传组件,通过上传图片后端识别图片里的人脸,感兴趣的可以了解一下
    2021-11-11
  • vue中keep-alive组件的用法示例

    vue中keep-alive组件的用法示例

    众所周知keep-alive是Vue提供的一个抽象组件,主要是用来对组件进行缓存,从而做到节省性能,这篇文章主要给大家介绍了关于vue中keep-alive组件用法的相关资料,需要的朋友可以参考下
    2021-05-05
  • vue实现书籍购物车功能

    vue实现书籍购物车功能

    这篇文章主要为大家详细介绍了vue实现书籍购物车功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-10-10
  • vue 解决setTimeOut和setInterval函数无效报错的问题

    vue 解决setTimeOut和setInterval函数无效报错的问题

    这篇文章主要介绍了vue 解决setTimeOut和setInterval函数无效报错的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-07-07
  • vue触发真实的点击事件跟用户行为一致问题

    vue触发真实的点击事件跟用户行为一致问题

    这篇文章主要介绍了vue触发真实的点击事件跟用户行为一致问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-03-03
  • vue使用自定义指令实现按钮权限展示功能

    vue使用自定义指令实现按钮权限展示功能

    这篇文章主要介绍了vue中使用自定义指令实现按钮权限展示功能,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-04-04
  • vue路由传参方式的方式总结及获取参数详解

    vue路由传参方式的方式总结及获取参数详解

    vue 路由传参的使用场景一般都是应用在父路由跳转到子路由时,携带参数跳转,下面这篇文章主要给大家介绍了关于vue路由传参方式的方式总结及获取参数的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-07-07
  • Element table 上下移需求的实现

    Element table 上下移需求的实现

    本文主要介绍了Element table 上下移需求的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-07-07

最新评论