使用Vue實現(xiàn)簡易的車牌輸入鍵盤
更新時間:2023年11月28日 11:08:29 作者:大陽光男孩
這篇文章主要為大家詳細介紹了如何使用Vue實現(xiàn)簡易的車牌輸入鍵盤效果,文中的示例代碼講解詳細,具有一定的學(xué)習(xí)價值,感興趣的小伙伴可以了解下
效果圖如下:

代碼如下:
<template>
<div>
<div class="carNoBoxInput">
<div style="padding: 6px;border: 2px solid #fff;border-radius: 6px;margin: 6px 3px 6px 6px;">
<input class="inputBox" :value="licensePlateUnit[0]" @click="licensePlateDoor = true"/>
<input class="inputBox" :value="licensePlateUnit[1]" @click="licensePlateDoor = true"/>
<span class="dot"></span>
<input class="inputBox" :value="licensePlateUnit[2]" @click="licensePlateDoor = true"/>
<input class="inputBox" :value="licensePlateUnit[3]" @click="licensePlateDoor = true"/>
<input class="inputBox" :value="licensePlateUnit[4]" @click="licensePlateDoor = true"/>
<input class="inputBox" :value="licensePlateUnit[5]" @click="licensePlateDoor = true"/>
<input class="inputBox" :value="licensePlateUnit[6]" @click="licensePlateDoor = true"/>
<input v-if="7 === licensePlateUnit.length - 1" class="inputBox" :class="7 === licensePlateUnit.length - 1 ? 'inputBoxActive' : 'inputBox'" :value="licensePlateUnit[7]"/>
<img v-if="7 !== licensePlateUnit.length - 1" src="../assets/newEnergy.png" style="height: 36px;width: 36px;" alt="新能源"/>
</div>
</div>
<div v-if="licensePlateDoor">
<div v-if="licensePlateUnit.length < 1" class="carNoBox">
<span class="carNo" v-for="item in columns" :key="item" @click="pickOn(item)">
{{item}}
</span>
<span class="delBt" @click="delCarNo">X</span>
</div>
<div v-if="licensePlateUnit.length >= 1" class="carNoBox">
<span class="carNo" v-for="item in numberColumns" :key="item" @click="pickOn(item)">
{{item}}
</span>
<div style="display: flex;align-items: center">
<span class="delBt" @click="delCarNo">X</span>
<span class="delBt" style="margin-left: 6px;width: 42px" @click="confirm">確認</span>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
licensePlateDoor: false,
activeIndex: 0,
licensePlateUnit: [],
columns: [//省縮寫選擇
'京', '滬', '鄂', '湘', '川', '渝', '粵', '閩', '晉', '黑',
'津', '浙', '豫', '贛', '貴', '青', '瓊', '寧', '吉', '蒙',
'冀', '蘇', '皖', '桂', '云', '陜', '甘', '藏', '新', '遼',
'魯'],
numberColumns: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0','Q', 'W', 'E',
'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z',
'X', 'C', 'V', 'B', 'N', 'M', '港','澳','學(xué)','領(lǐng)','警'
],
}
},
methods: {
pickOn(value) {
this.licensePlateDoor = true;
if (this.licensePlateUnit.length <= 7) {
this.licensePlateUnit.push(value)
}
},
delCarNo() {
this.licensePlateUnit.pop();
},
confirm() {
if(this.licensePlateUnit.length >= 7) {
console.log("車牌是:"+this.licensePlateUnit.join(''));
this.licensePlateDoor = false;
}
},
}
}
</script>
<style scoped>
.carNo {
border-radius: 6px;
background: #fff;
font-weight: bold;
font-size: 20px;
height: 28px;
width:28px;
margin: 6px;
padding: 12px;
cursor: pointer;
}
.inputBox {
color: white;
height: 30px;
line-height: 30px;
width: 30px;
font-size: 28px;
text-align: center;
background-color: transparent;
border: none;
outline: none;
caret-color: rgba(0, 0, 0, 0)
}
input:focus {
border-bottom: 3px solid #fff;
transition: all 0.5s;
}
.dot {
margin-bottom: 6px;
background-color: #fff;
height: 6px;
width: 6px;
border-radius: 50%;
display: inline-block
}
.delBt {
background: #ACB3BB;
border-radius: 6px;
display: inline-block;
font-weight: bold;
font-size: 20px;
height: 28px;
width:28px;
margin: 6px;
padding: 12px;
cursor: pointer;
}
.carNoBoxInput {
display: flex;
width: 310px;
align-items: center;
//height: 80px;
border-radius: 8px;
margin: 12px 0;
background: #2D66D8;
}
.carNoBox {
background: #D0D5D9;
position: relative;
width: 600px;
border-radius: 6px;
display: flex;
flex-wrap: wrap;
justify-items: center;
align-items: center
}
</style>到此這篇關(guān)于使用Vue實現(xiàn)簡易的車牌輸入鍵盤的文章就介紹到這了,更多相關(guān)Vue車牌輸入鍵盤內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
element-ui循環(huán)顯示radio控件信息的方法
今天小編就為大家分享一篇element-ui循環(huán)顯示radio控件信息的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue+axios實現(xiàn)圖片上傳識別人臉的示例代碼
本文主要介紹了vue+axios實現(xiàn)圖片上傳識別人臉,這里采用的是vant的文件上傳組件,通過上傳圖片后端識別圖片里的人臉,感興趣的可以了解一下2021-11-11
vue 解決setTimeOut和setInterval函數(shù)無效報錯的問題
這篇文章主要介紹了vue 解決setTimeOut和setInterval函數(shù)無效報錯的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
vue使用自定義指令實現(xiàn)按鈕權(quán)限展示功能
這篇文章主要介紹了vue中使用自定義指令實現(xiàn)按鈕權(quán)限展示功能,本文結(jié)合實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04
vue路由傳參方式的方式總結(jié)及獲取參數(shù)詳解
vue 路由傳參的使用場景一般都是應(yīng)用在父路由跳轉(zhuǎn)到子路由時,攜帶參數(shù)跳轉(zhuǎn),下面這篇文章主要給大家介紹了關(guān)于vue路由傳參方式的方式總結(jié)及獲取參數(shù)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-07-07

