<div class="smsCode">
<div
v-for="(item,index) in codeList"
:key="index"
class="codeItem">
{{ smsCode[index] || '' }}
<div :style="{background: smsCode[index] ? '#999' : ''}" class="border"/>
<div class="line" v-if="smsCode.length === index"/>
</div>
<input ref="inputRef" v-model="smsCode" class="codeInput" type="number" maxlength="6" @input="inputChange"
pattern="[0-9]*"/>
</div>
return {
smsCode: '',
codeList: [],
};
this.codeList = new Array(6).fill("")
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none !important;
margin: 0;
}
input {
caret-color: transparent; // 修改input自带的光标颜色
}
.smsCode {
display: flex;
height: 67px;
flex-direction: row;
justify-content: space-around;
position: relative;
}
.codeInput {
height: 67px;
position: absolute;
border: none;
outline: none;
color: transparent;
background-color: transparent;
text-shadow: 0 0 0 transparent;
}
// 光标
.line {
opacity: 0;
animation-name: flicker;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-duration: .5s;
animation-direction: alternate;
position: absolute;
top: 26px;
left: 14px;
width: 2px;
height: 25px;
border-radius: 2px;
background: #999;
}
@keyframes flicker {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.codeItem {
position: relative;
width: 30px;
padding-top: 17px;
font-size: 36px;
line-height: 42px;
padding-bottom: 5px;
color: #333333;
}
.border {
position: absolute;
content: "";
bottom: 0;
left: 0;
width: 30px;
height: 3px;
background: #E9E9E9;
border-radius: 2px;
}
