Skip to content

input.vue $root.$on

Carl's edited this page Jun 4, 2021 · 5 revisions

input.vue 接收事件

int类型input

case 1: 有效整数

  • preset
let intValue="";
<ky-input v-model="intValue" type="int" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],1);
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">1</span>`
  • return true

case 2: 接收浮动数字

  • preset
 let intValue="";
<ky-input v-model="intValue" type="int" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],1.1);
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==``
  • return false

case 3: 自定义规则

  • preset
let intValue="";
  <ky-input
      v-model="value1"
      :regx="/^[\d%+-/]+$/gi"
      type="int"
      @submit="submitFn"
      class="hahahha"
    />
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],"%");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">%</span>`
  • return true

float类型input

case 1: 整数

  • preset
let intValue="";
<ky-input v-model="intValue" type="int" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],1);
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`1`
  • return true (是运行输入整数的,因为1.12这样的小数也是分别由用户输入"1",".","1","2"的)

case 2: 接收浮动数字

  • preset
 let intValue="";
<ky-input v-model="intValue" type="int" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],1.12);
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">1.12</span>`
  • return true

case 2: 接收浮动数字 大于默认小数个数

  • preset
 let intValue="";
<ky-input v-model="intValue" type="int" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],1.123);
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">1.123</span>`
  • return false 不允许输入超过限制长度的小数

cn类型input

case 1: 有效整数,可输入

  • preset
let intValue="";
<ky-input v-model="intValue" type="cn" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],"你");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">你</span>`
  • return true

case 2: 带中文·符号,可输入

  • preset
 let intValue="";
<ky-input v-model="intValue" type="cn" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],"你·你");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">你·你</span>`
  • return true

case 3: 带中文其他符号(无法输入)

  • preset
 let intValue="";
<ky-input v-model="intValue" type="cn" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],",");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==``
  • return true

en类型input

case 1: 有效字母,可输入

  • preset
let intValue="";
<ky-input v-model="intValue" type="en" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],"z");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">z</span>`
  • return true

case 2: 大写(可输入)

  • preset
 let intValue="";
<ky-input v-model="intValue" type="en" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],"Z");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==`<span class="vue-keyboard-text-item" tabindex="0">Z</span>`
  • return true

case 3: 带英文符号(无法输入)

  • preset
 let intValue="";
<ky-input v-model="intValue" type="en" /> 
this.$root.$emit(EventKeys["vue-keyboard-cn-append-item"],",");
  • test
document.querySelector(".vue-keyboard-input-text").innerHTML==``
  • return true
Clone this wiki locally