欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue使用虛擬鍵盤及中英文切換功能

 更新時間:2023年06月29日 16:06:50   作者:惟愿君安  
這篇文章主要給大家介紹了關(guān)于Vue使用虛擬鍵盤及中英文切換的相關(guān)資料,有時候在大型觸屏設(shè)備(如雙屏設(shè)備)中往往就沒有鍵盤去操作,所以就需要去建立一個虛擬鍵盤去操作,需要的朋友可以參考下

1.安裝依賴

npm install simple-keyboard --save
npm install simple-keyboard-layouts --save

2.虛擬鍵盤組件

simpleKeyboard.vue

<template>
  <div :class="keyboardClass"></div>
</template>
<script>
import Keyboard from 'simple-keyboard'
import 'simple-keyboard/build/css/index.css'
import layout from 'simple-keyboard-layouts/build/layouts/chinese' // 中文輸入法
export default {
  name: 'SimpleKeyboard',
  props: {
    keyboardClass: {
      default: 'simple-keyboard',
      type: String,
    },
    input: {
      default: '',
    },
    maxLength: { default: '' },
  },
  data: () => ({
    keyboard: null,
    displayDefault: {
      '{bksp}': 'backspace',
      '{lock}': 'caps',
      '{enter}': '> enter',
      '{tab}': 'tab',
      '{shift}': 'shift',
      '{change}': '中文',
      '{space}': ' ',
      '{clear}': '清空',
      '{close}': '關(guān)閉',
    },
  }),
  mounted() {
    this.keyboard = new Keyboard(this.keyboardClass, {
      onChange: this.onChange,
      onKeyPress: this.onKeyPress,
      layoutCandidates: layout.layoutCandidates,
      layout: {
        // 默認(rèn)布局
        default: [
          '` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
          '{tab} q w e r t y u i o p [ ] \\',
          "{lock} a s d f g h j k l ; ' {enter}",
          '{shift} z x c v b n m , . / {clear}',
          '{change} {space} {close}',
        ],
        // shift布局
        shift: [
          '~ ! @ # $ % ^ & * ( ) _ + {bksp}',
          '{tab} Q W E R T Y U I O P { } |',
          '{lock} A S D F G H J K L : " {enter}',
          '{shift} Z X C V B N M < > ? {clear}',
          '{change} {space} {close}',
        ],
      },
      // 按鈕展示文字
      display: this.displayDefault,
      // 按鈕樣式
      buttonTheme: [
        {
          class: 'hg-red close',
          buttons: '{close}',
        },
        {
          class: 'change',
          buttons: '{change}',
        },
      ],
      // 輸入限制長度
      maxLength: this.maxLength,
    })
  },
  methods: {
    onChange(input) {
      this.keyboard.setInput(input)
      this.$emit('onChange', input)
    },
    // 點擊鍵盤
    onKeyPress(button, $event) {
      console.log(button)
      // 點擊關(guān)閉
      if (button === '{close}') {
        // let keyboard = $event.path[3]
        // 子組件調(diào)用父組件的關(guān)閉按鈕方法
        this.$parent.closekeyboard()
        // keyboard.style.visibility = 'hidden'
        return false
      } else if (button === '{change}') {
        // 切換中英文輸入法
        if (this.keyboard.options.layoutCandidates !== null) {
          this.$set(this.displayDefault, '{change}', '英文')
          // 切換至英文
          this.keyboard.setOptions({
            layoutCandidates: null,
            display: this.displayDefault,
          })
        } else {
          // 切換至中文
          this.$set(this.displayDefault, '{change}', '中文')
          this.keyboard.setOptions({
            layoutCandidates: layout.layoutCandidates,
            display: this.displayDefault,
          })
        }
      } else if (button === '{clear}') {
        this.keyboard.clearInput()
      } else {
        let value =
          $event.target.offsetParent.parentElement.children[0].children[0].value
        // 輸入框有默認(rèn)值時,覆寫
        if (value) {
          this.keyboard.setInput(value)
        }
        this.$emit('onKeyPress', button)
      }
      if (button === '{shift}' || button === '{lock}') this.handleShift()
    },
    // 切換shift/默認(rèn)布局
    handleShift() {
      let currentLayout = this.keyboard.options.layoutName
      let shiftToggle = currentLayout === 'default' ? 'shift' : 'default'
      this.keyboard.setOptions({
        layoutName: shiftToggle,
      })
    },
  },
  watch: {
    input(input) {
      this.keyboard.setInput(input)
    },
  },
}
</script>
<style lang="less">
@deep: ~'>>>';
.hg-theme-default {
  width: 70%;
  .hg-button {
    &.hg-red {
      background: #db3e5d;
      color: white;
      &.close {
        max-width: 200px;
      }
    }
    &.change {
      max-width: 200px;
    }
  }
}
</style>

3.使用虛擬鍵盤 

<el-input v-model="toolParameter.latheNumber" @focus="onInputFocus('latheNumber')">
</el-input>
 
<el-input v-model="toolParameter.tid" @focus="onInputFocus('tid')" placeholder="">
</el-input>
 
<div v-show="showKeyboard">
      <SimpleKeyboard ref="SimpleKeyboard" @onChange="onChangeKeyboard" />
</div>
 
import SimpleKeyboard from '../../components/simpleKeyboard.vue'
export default {
  name: 'Home',
   components: {
    SimpleKeyboard,
   },
   data() {
    return {
        showKeyboard: false, //鍵盤默認(rèn)隱藏
        changeIpt:'',//選擇了哪個輸入框
    }
   },
   
   methods:{
    // inpuit獲取焦點顯示虛擬鍵盤
    onInputFocus(res) {
      this.showKeyboard = true
      this.changeIpt = res
      // 父組件調(diào)用子組件的方法
      this.$refs.SimpleKeyboard.onKeyPress('{clear}')
    },
 // 給輸入框賦值
    onChangeKeyboard(input) {
      if (this.changeIpt == 'latheNumber') {
        this.toolParameter.latheNumber = input
      } else if (this.changeIpt == 'tid') {
        this.toolParameter.tid = input
      }
    },
    // 點擊關(guān)閉隱藏鍵盤
    closekeyboard() {
      this.showKeyboard = false
    },
   }
}
// 鍵盤樣式
.simple-keyboard {
  position: absolute;
  bottom: 0;
  left: 5%;
  width: 90%;
  color: #000;
  z-index: 999999999;
}

總結(jié)

到此這篇關(guān)于Vue使用虛擬鍵盤及中英文切換的文章就介紹到這了,更多相關(guān)Vue使用虛擬鍵盤內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用Vue實現(xiàn)點擊按鈕小球加入購物車動畫

    使用Vue實現(xiàn)點擊按鈕小球加入購物車動畫

    這篇文章主要為大家詳細介紹了如何使用Vue實現(xiàn)點擊按鈕小球加入購物車動畫,文中的示例代碼講解詳細,有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • vuejs2.0運用原生js實現(xiàn)簡單的拖拽元素功能示例

    vuejs2.0運用原生js實現(xiàn)簡單的拖拽元素功能示例

    本篇文章主要介紹了vuejs2.0運用原生js實現(xiàn)簡單的拖拽元素功能示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-02-02
  • Vue條件渲染與列表渲染

    Vue條件渲染與列表渲染

    這篇文章主要介紹了Vue條件渲染與列表渲染,條件渲染包括v-if、v-show等內(nèi)容,文章對條件渲染及列表渲染介紹詳細,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-05-05
  • Vuejs第十二篇之動態(tài)組件全面解析

    Vuejs第十二篇之動態(tài)組件全面解析

    組件(Component)是 Vue.js 最強大的功能之一。組件可以擴展 HTML 元素,封裝可重用的代碼。接下來通過本文給大家介紹Vuejs第十二篇之動態(tài)組件,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-09-09
  • vue2+elementUI的el-tree的懶加載功能

    vue2+elementUI的el-tree的懶加載功能

    這篇文章主要介紹了vue2+elementUI的el-tree的懶加載,文中給大家提到了element?ui?中?el-tree?實現(xiàn)懶加載的方法,本文結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2022-09-09
  • 使用Vue實現(xiàn)簡單日歷效果

    使用Vue實現(xiàn)簡單日歷效果

    這篇文章主要為大家詳細介紹了使用Vue實現(xiàn)簡單日歷效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Vue3?watchEffect的使用教程和相關(guān)概念

    Vue3?watchEffect的使用教程和相關(guān)概念

    Vue?3?引入了?Composition?API,其中?watchEffect?是一個非常強大的工具,用于響應(yīng)式地追蹤依賴項的變化,本文將詳細介紹?watchEffect?的使用方法和相關(guān)概念,文中有詳細的代碼供大家參考,需要的朋友可以參考下
    2024-08-08
  • Vue?3?使用moment設(shè)置顯示時間格式的問題及解決方法

    Vue?3?使用moment設(shè)置顯示時間格式的問題及解決方法

    在Vue?3中,因為過濾器(filter)已經(jīng)被廢棄,取而代之的是全局方法(global?method),本文給大家介紹Vue?3?使用moment設(shè)置顯示時間格式的問題及解決方法,感興趣的朋友一起看看吧
    2023-12-12
  • vite+vue3+ts項目新建以及解決遇到的問題

    vite+vue3+ts項目新建以及解決遇到的問題

    vite是一個基于Vue3單文件組件的非打包開發(fā)服務(wù)器,它具有快速的冷啟動,不需要等待打包操作,下面這篇文章主要給大家介紹了關(guān)于vite+vue3+ts項目新建以及解決遇到的問題的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • vue項目調(diào)試的三種方法總結(jié)

    vue項目調(diào)試的三種方法總結(jié)

    這篇文章主要給大家總結(jié)介紹了關(guān)于vue項目調(diào)試的三種方法,大家可以根據(jù)需要選擇調(diào)試方法,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2023-09-09

最新評論