博客
关于我
一个车牌输入组件(vue)
阅读量:386 次
发布时间:2019-03-05

本文共 1900 字,大约阅读时间需要 6 分钟。

基于Vue的简单车牌输入组件实现

功能展示

该车牌输入组件支持多种车牌结构输入,包括省份代码、数字和其他特殊字符。组件采用点击输入的方式,支持字符的逐步输入和删除操作。

代码结构

## 事件处理```javascriptclickInput(type) { this.plateInput.input.type = type; this.plateInput.input.dialogVisible = true;}hiddenKeybord() { this.plateInput.input.dialogVisible = false;}enterWord() { this.plateInput.input.dialogVisible = false;}

方法实现

clickKeyboard(val) {  if (this.plateInput.input.type === 'p2' && parseInt(val) >= 0 && parseInt(val) <= 9) return;  this.methods('clickKeyboard', val);  this.methods('setPlateNumber');  this.methods('setDirectIssuedPlateNumber');}clickDelete() {  this.plateInput.input.value[this.plateInput.input.type] = undefined;  let nu = parseInt(this.plateInput.input.type.split('p')[1]) - 1;  if (nu >= 0) {    this.plateInput.input.value['p' + nu] = undefined;  }  let type = this.plateInput.input.type.split('p')[1];  if (type !== '1') {    this.plateInput.input.type = 'p' + (parseInt(type) - 1);  }}

数据模型

export let model = {  currentPlate: undefined,  plateInput: {    input: {      value: {        p1: '桂',        p2: 'B',        p3: 2,        p4: 2,        p5: 2,        p6: 2,        p7: 2,        p8: 0      },      type: 'p1',      dialogVisible: false    }  },  Keyboard: {    province: ['京', '津', '冀', '晋', '蒙', '辽', '吉', '黑', '沪', '苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤', '桂', '琼', '渝', '川', '贵', '云', '藏', '陕', '甘', '青', '宁', '新', '台', '港', '澳', '使', '领', '警', '学'],    number: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '学', '港', '澳']  }}

代码优化建议

  • 去除所有无效的空白div标签
  • 合并重复的样式表
  • 使用更优化的变量命名
  • 增加注释,提升代码可读性
  • 优化键盘事件响应逻辑
  • 增加字符验证功能,避免非法字符输入
  • 转载地址:http://ksgwz.baihongyu.com/

    你可能感兴趣的文章
    Notepad++在线和离线安装JSON格式化插件
    查看>>
    notepad++最详情汇总
    查看>>
    notepad++正则表达式替换字符串详解
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notes on Paul Irish's "Things I learned from the jQuery source" casts
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    NotImplementedError: Could not run torchvision::nms
    查看>>
    nova基于ubs机制扩展scheduler-filter
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>