最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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}': '關閉',
    },
  }),
  mounted() {
    this.keyboard = new Keyboard(this.keyboardClass, {
      onChange: this.onChange,
      onKeyPress: this.onKeyPress,
      layoutCandidates: layout.layoutCandidates,
      layout: {
        // 默認布局
        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)
      // 點擊關閉
      if (button === '{close}') {
        // let keyboard = $event.path[3]
        // 子組件調用父組件的關閉按鈕方法
        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
        // 輸入框有默認值時,覆寫
        if (value) {
          this.keyboard.setInput(value)
        }
        this.$emit('onKeyPress', button)
      }
      if (button === '{shift}' || button === '{lock}') this.handleShift()
    },
    // 切換shift/默認布局
    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, //鍵盤默認隱藏
        changeIpt:'',//選擇了哪個輸入框
    }
   },
   
   methods:{
    // inpuit獲取焦點顯示虛擬鍵盤
    onInputFocus(res) {
      this.showKeyboard = true
      this.changeIpt = res
      // 父組件調用子組件的方法
      this.$refs.SimpleKeyboard.onKeyPress('{clear}')
    },
 // 給輸入框賦值
    onChangeKeyboard(input) {
      if (this.changeIpt == 'latheNumber') {
        this.toolParameter.latheNumber = input
      } else if (this.changeIpt == 'tid') {
        this.toolParameter.tid = input
      }
    },
    // 點擊關閉隱藏鍵盤
    closekeyboard() {
      this.showKeyboard = false
    },
   }
}
// 鍵盤樣式
.simple-keyboard {
  position: absolute;
  bottom: 0;
  left: 5%;
  width: 90%;
  color: #000;
  z-index: 999999999;
}

總結

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

相關文章

  • Vue-cli-webpack搭建斗魚直播步驟詳解

    Vue-cli-webpack搭建斗魚直播步驟詳解

    斗魚直播是比較火的直播視頻,想必大家都看過吧。這篇文章主要介紹了Vue-cli-webpack搭建斗魚直播步驟詳解,需要的朋友可以參考下
    2017-11-11
  • Vue中消息橫向滾動時setInterval清不掉的問題及解決方法

    Vue中消息橫向滾動時setInterval清不掉的問題及解決方法

    最近在做項目時,需要進行兩個組件聯(lián)動,一個輪詢獲取到消息,然后將其傳遞給另外一個組件進行橫向滾動展示,結果滾動的速度越來越快。接下來通過本文給大家分享Vue中消息橫向滾動時setInterval清不掉的問題及解決方法,感興趣的朋友一起看看吧
    2019-08-08
  • Vue 動態(tài)組件components和v-once指令的實現(xiàn)

    Vue 動態(tài)組件components和v-once指令的實現(xiàn)

    這篇文章主要介紹了Vue 動態(tài)組件components和v-once指令的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • vue3繼承并擴展三方組件完成二次封裝的示例詳解

    vue3繼承并擴展三方組件完成二次封裝的示例詳解

    這篇文章主要介紹了vue3繼承并擴展三方組件完成二次封裝,文章使用naiveui的Input組件進行舉例,elementPlus或者其他組件庫同理,并通過代碼示例講解的非常詳細,需要的朋友可以參考下
    2024-03-03
  • Vue編寫多地區(qū)選擇組件

    Vue編寫多地區(qū)選擇組件

    這篇文章主要為大家詳細介紹了Vue編寫一個挺靠譜的多地區(qū)選擇組件的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • vue項目打包發(fā)布后接口報405錯誤的解決

    vue項目打包發(fā)布后接口報405錯誤的解決

    這篇文章主要介紹了vue項目打包發(fā)布后接口報405錯誤的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • vue面試created中兩次數(shù)據(jù)修改會觸發(fā)幾次頁面更新詳解

    vue面試created中兩次數(shù)據(jù)修改會觸發(fā)幾次頁面更新詳解

    這篇文章主要為大家介紹了vue面試created中兩次數(shù)據(jù)修改會觸發(fā)幾次頁面更新問題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • vue綁定class的三種方法

    vue綁定class的三種方法

    這篇文章主要介紹了vue綁定class的三種方法,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下
    2020-12-12
  • Vue實現(xiàn)大屏獲取當前所處城市及當?shù)靥鞖獾木唧w方案

    Vue實現(xiàn)大屏獲取當前所處城市及當?shù)靥鞖獾木唧w方案

    文章介紹了如何在大屏項目中展示城市名稱和實時天氣信息,通過瀏覽器的GeolocationAPI獲取經(jīng)緯度,然后使用逆地理編碼服務獲取城市名稱,文章還提到了使用Open-Meteo獲取天氣信息,該服務免費且支持全球經(jīng)緯度的實時天氣和未來7天預報,需要的朋友可以參考下
    2026-02-02
  • vue2.0實現(xiàn)倒計時的插件(時間戳 刷新 跳轉 都不影響)

    vue2.0實現(xiàn)倒計時的插件(時間戳 刷新 跳轉 都不影響)

    我發(fā)現(xiàn)好多倒計時的插件,刷新都會變成從頭再來,于是自己用vue2.0寫了一個,感覺還不錯,特此分享到腳本之家平臺供大家參考下
    2017-03-03

最新評論

桓台县| 盱眙县| 固镇县| 翁牛特旗| 禹州市| 八宿县| 渝中区| 兴海县| 巍山| 定边县| 八宿县| 南投市| 绥阳县| 龙门县| 福建省| 德安县| 上栗县| 固始县| 托克托县| 江门市| 秦安县| 如东县| 苏州市| 天长市| 荔波县| 会宁县| 公安县| 铁岭县| 瑞丽市| 左贡县| 淮南市| 河曲县| 东莞市| 新干县| 大理市| 秦皇岛市| 安乡县| 大宁县| 永嘉县| 大足县| 九龙坡区|