vue實(shí)現(xiàn)移動(dòng)端H5數(shù)字鍵盤(pán)組件使用詳解
本文實(shí)例為大家分享了vue實(shí)現(xiàn)移動(dòng)端H5數(shù)字鍵盤(pán)組件的使用代碼,供大家參考,具體內(nèi)容如下
我們平時(shí)掃碼付款的時(shí)候,經(jīng)常會(huì)輸入一些數(shù)字進(jìn)行付款,仔細(xì)看了下鍵盤(pán)和系統(tǒng)的鍵盤(pán)有點(diǎn)不一樣,于是今天買甘蔗的時(shí)候掃碼付款就想了一下要怎么去實(shí)現(xiàn)一個(gè)。話不多說(shuō),直接上代碼。
結(jié)果如下:

代碼如下:
<template>
<div class="keyboard-wrapper">
<input type="text" v-model="NUM" @focus="show = true" onfocus="this.blur()"/>
<div class="keyboard" v-if="show">
<div class="num">
<table>
<tr>
<td @click="change(1)" :class="[active === 1 ? 'active' : '']" @touchstart="msDown(1)" @touchend="msUp(1)">1</td>
<td @click="change(2)" :class="[active === 2 ? 'active' : '']" @touchstart="msDown(2)" @touchend="msUp(2)">2</td>
<td @click="change(3)" :class="[active === 3 ? 'active' : '']" @touchstart="msDown(3)" @touchend="msUp(3)">3</td>
<td rowspan="2" class="del" @click="del">×</td>
</tr>
<tr>
<td @click="change(4)" :class="[active === 4 ? 'active' : '']" @touchstart="msDown(4)" @touchend="msUp(4)">4</td>
<td @click="change(5)" :class="[active === 5 ? 'active' : '']" @touchstart="msDown(5)" @touchend="msUp(5)">5</td>
<td @click="change(6)" :class="[active === 6 ? 'active' : '']" @touchstart="msDown(6)" @touchend="msUp(6)">6</td>
</tr>
<tr>
<td @click="change(7)" :class="[active === 7 ? 'active' : '']" @touchstart="msDown(7)" @touchend="msUp(7)">7</td>
<td @click="change(8)" :class="[active === 8 ? 'active' : '']" @touchstart="msDown(8)" @touchend="msUp(8)">8</td>
<td @click="change(9)" :class="[active === 9 ? 'active' : '']" @touchstart="msDown(9)" @touchend="msUp(9)">9</td>
<td rowspan="2" class="comfirm" @click="comfirm">確定</td>
</tr>
<tr>
<td colspan="2" @click="change(0)" :class="[active === 0 ? 'active' : '']" @touchstart="msDown(0)" @touchend="msUp(0)">0</td>
<td colspan="1" @click="change('.')" :class="[active === '.' ? 'active' : '']" @touchstart="msDown('.')" @touchend="msUp('.')">.</td>
</tr>
</table>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
active: null,
show: false,
NUM: '',
result: []
};
},
computed: {
// 統(tǒng)計(jì)打中的地鼠數(shù)量
num: function () {
return this.result.join('');
}
},
created () {
},
mounted () {
},
methods: {
msDown (v) {
this.active = v;
},
msUp (v) {
this.active = '';
},
stopInput () {
return false;
},
change (val, $event) {
if (this.result.length === 0 && val === '.') {
return false;
} else {
this.result.push(val);
this.NUM = this.result.join('');
}
},
del () {
this.result.pop();
this.NUM = this.result.join('');
this.$emit('del', this.NUM);
},
comfirm () {
this.$emit('comfirm', this.NUM);
this.show = false;
}
}
};
</script>
<style lang="less" scoped>
.keyboard-wrapper {
user-select: none;
input {
width:100%;
height:50px;
font-size:25px;
}
.keyboard {
position: fixed;
bottom: 0;
width: 100%;
.num {
table {
width: 100%;
border: 1px solid #ccc;
border-collapse: collapse;
background: #fff;
td {
height: 50px;
vertical-align: middle;
color: #333;
font-size: 20px;
border: 1px solid #ccc;
text-align: center;
}
td.active{
background:#ccc;
}
.del {
background: #eee;
}
.comfirm {
font-size: 16px;
width: 80px;
background: #118eeb;
color: #fff;
}
}
}
}
}
</style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue2?this?能夠直接獲取到?data?和?methods?的原理分析
這篇文章主要介紹了Vue2?this能夠直接獲取到data和methods的原理分析,因?yàn)閙ethods里的方法通過(guò)bind指定了this為new?Vue的實(shí)例2022-06-06
vite打包只生成了一個(gè)css和js文件問(wèn)題的解決方法
今天整了一個(gè)項(xiàng)目,試了下打包,發(fā)下打包后只生成了一個(gè)css文件,和一個(gè)js文件,這樣肯定是不行的,因?yàn)檫@樣這個(gè)文件的包大小很大,第一次訪問(wèn)會(huì)導(dǎo)致白屏問(wèn)題,所以本文給大家介紹了vite打包只生成了一個(gè)css和js文件問(wèn)題的解決方法,需要的朋友可以參考下2024-05-05
JavaScript之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的Vue示例
這篇文章主要介紹了JavaScript之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的Vue示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01
iview+vue實(shí)現(xiàn)導(dǎo)入EXCEL預(yù)覽功能
這篇文章主要為大家詳細(xì)介紹了iview+vue實(shí)現(xiàn)導(dǎo)入EXCEL預(yù)覽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
詳解element-ui動(dòng)態(tài)限定的日期范圍選擇器代碼片段
這篇文章主要介紹了element-ui動(dòng)態(tài)限定的日期范圍選擇器代碼片段,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
Nuxt3:拉取項(xiàng)目模板失敗問(wèn)題以及解決
文章描述了在使用官網(wǎng)命令創(chuàng)建Nuxt3項(xiàng)目時(shí)遇到的問(wèn)題,通過(guò)分析命令,推測(cè)問(wèn)題出在拉取項(xiàng)目模板失敗,解決方法是手動(dòng)訪問(wèn)并下載項(xiàng)目模板,解壓后按照官網(wǎng)教程安裝依賴并啟動(dòng),最終成功解決問(wèn)題2024-12-12

