国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

vue實現驗證碼輸入框組件

來源:懂視網 責編:小采 時間:2020-11-27 22:23:41
文檔

vue實現驗證碼輸入框組件

vue實現驗證碼輸入框組件:先來看波完成效果圖 需求 輸入4位或6位短信驗證碼,輸入完成后收起鍵盤 實現步驟 第一步 布局排版 <div class=security-code-wrap> <label for=code> <ul class=security-code-container>
推薦度:
導讀vue實現驗證碼輸入框組件:先來看波完成效果圖 需求 輸入4位或6位短信驗證碼,輸入完成后收起鍵盤 實現步驟 第一步 布局排版 <div class=security-code-wrap> <label for=code> <ul class=security-code-container>

先來看波完成效果圖

 

需求

輸入4位或6位短信驗證碼,輸入完成后收起鍵盤

實現步驟

第一步

布局排版

<div class="security-code-wrap">
 <label for="code">
 <ul class="security-code-container">
 <li class="field-wrap" v-for="(item, index) in number" :key="index">
 <i class="char-field">{{value[index] || placeholder}}</i>
 </li>
 </ul>
 </label>
 <input ref="input" class="input-code" @keyup="handleInput($event)" v-model="value"
 id="code" name="code" type="tel" :maxlength="number"
 autocorrect="off" autocomplete="off" autocapitalize="off">
</div>

使用li元素來模擬輸入框的顯示,沒有別的目的,就只是為了語義化,當然你也可以使用其他任意一個元素來模擬,比如div。

使用label標簽的好處在于它可以跟input的click事件關聯上,一方面實現了語義化解決方案,另一方面也省去了我們通過js來喚起虛擬鍵盤。

隱藏輸入框

.input-code {
 position: absolute;
 left: -9999px;
 top: -99999px;
 width: 0;
 height: 0;
 opacity: 0;
 overflow: visible;
 z-index: -1;
}

將真實的輸入框定位到屏幕可視區域以外的地方,虛擬鍵盤被喚起時,就不會將頁面往上頂了。所以你的驗證碼輸入組件一定要放在虛擬鍵盤遮擋不了的地方。

第二步

處理驗證碼輸入

handleSubmit() {
 this.$emit('input', this.value)
},
handleInput(e) {
 this.$refs.input.value = this.value
 if (this.value.length >= this.number) {
 this.hideKeyboard()
 }
 this.handleSubmit()
}

輸入時,給輸入框賦一次值,是為了解決android端上輸入框失焦后重新聚焦,輸入光標會定在第一位的前面,經過賦值再聚焦,光標的位置就會顯示在最后一位后面。

第三步

完成輸入后關閉虛擬鍵盤

hideKeyboard() {
 // 輸入完成隱藏鍵盤
 document.activeElement.blur() // ios隱藏鍵盤
 this.$refs.input.blur() // android隱藏鍵盤
}

組件完整代碼

<!--四位驗證碼輸入框組件-->
<template>
 <div class="security-code-wrap">
 <label for="code">
 <ul class="security-code-container">
 <li class="field-wrap" v-for="(item, index) in number" :key="index">
 <i class="char-field">{{value[index] || placeholder}}</i>
 </li>
 </ul>
 </label>
 <input ref="input" class="input-code" @keyup="handleInput($event)" v-model="value"
 id="code" name="code" type="tel" :maxlength="number"
 autocorrect="off" autocomplete="off" autocapitalize="off">
 </div>
</template>
<script>
 export default {
 name: 'SecurityCode',
 // component properties
 props: {
 number: {
 type: Number,
 default: 4
 },
 placeholder: {
 type: String,
 default: '-'
 }
 },
 // variables
 data() {
 return {
 value: ''
 }
 },
 methods: {
 hideKeyboard() {
 // 輸入完成隱藏鍵盤
 document.activeElement.blur() // ios隱藏鍵盤
 this.$refs.input.blur() // android隱藏鍵盤
 },
 handleSubmit() {
 this.$emit('input', this.value)
 },
 handleInput(e) {
 this.$refs.input.value = this.value
 if (this.value.length >= this.number) {
 this.hideKeyboard()
 }
 this.handleSubmit()
 }
 }
 }
</script>
<style scoped lang="less">
 .security-code-wrap {
 overflow: hidden;
 }
 .security-code-container {
 margin: 0;
 padding: 0;
 display: flex;
 justify-content: center;
 .field-wrap {
 list-style: none;
 display: block;
 width: 40px;
 height: 40px;
 line-height: 40px;
 font-size: 16px;
 background-color: #fff;
 margin: 2px;
 color: #000;
 .char-field {
 font-style: normal;
 }
 }
 }
 .input-code {
 position: absolute;
 left: -9999px;
 top: -99999px;
 width: 0;
 height: 0;
 opacity: 0;
 overflow: visible;
 z-index: -1;
 }
</style>

組件使用代碼

<security-code v-model="authCode"></security-code>

總結

以上所述是小編給大家介紹的vue實現驗證碼輸入框組件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

vue實現驗證碼輸入框組件

vue實現驗證碼輸入框組件:先來看波完成效果圖 需求 輸入4位或6位短信驗證碼,輸入完成后收起鍵盤 實現步驟 第一步 布局排版 <div class=security-code-wrap> <label for=code> <ul class=security-code-container>
推薦度:
標簽: VUE 組件 輸入框
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 成人免费久久精品国产片久久影院 | 欧美国产亚洲一区二区三区 | 激情专区 | 九九精品视频一区二区三区 | 伊人情人综合成人久久网小说 | 国产精品久久久久… | 成人国内精品久久久久影院 | 91精品国产91久久综合 | 日韩专区亚洲综合久久 | 日韩亚洲欧美日本精品va | 日韩免费播放 | 97热久久免费频精品99国产成人 | 欧美v在线 | 亚洲日韩欧美视频 | 国内一级野外a一级毛片 | 亚洲欧洲日产国码一级毛片 | 国产高清免费视频 | 国产精品网站在线进入 | 欧美第一页在线 | 欧美日韩亚洲无线码在线观看 | 伊人久久大香线蕉综合爱婷婷 | 国产中文字幕视频 | 国产偷亚洲偷欧美偷精品 | 日韩另类 | 一区不卡在线观看 | 久久91精品国产91久久 | 国产免费一区二区三区免费视频 | 午夜免费福利视频 | 国产手机精品一区二区 | 欧美综合亚洲 | 国产中的精品一区的 | 欧美成人猛男性色生活 | 欧美日韩综合精品一区二区三区 | 中文字字幕 | 日韩欧美电影在线观看 | 欧美系列在线 | 国产精品久久久天天影视香蕉 | 91久久精品国产91性色tv | 欧美精品亚洲精品 | 久久艹精品| 亚洲91视频|