上一篇文章,我们使用react来模拟了类似移动端的这种密码输入效果,见详见链接,在这篇中,我们使用vue来实现类似的效果,思路基本和上一篇类型。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<div class="code-wrapper">
<div class="code-item" v-for="(index, item) in number" :key="index">
{{ code[item] }}
</div>
<input
class="code-input"
v-model="code"
:maxlength="number"
@input="inputOn"
type="text"
oninput="if(value.length>5)value=value.slice(0,6)"
/>
</div>
</template>
<script>
export default {
data() {
return {
code: "",
number: 6,
};
},
methods: {
inputOn() {
// 发送
// if (this.code.length >= this.number) {
// this.$emit('senCode', this.code)
// }
},
},
};
</script>

<style lang="less" scoped>
.code-wrapper {
position: relative;
width: 100%;
display: flex;
justify-content: space-between;
font-weight: bold;
.code-item {
width: 1.82rem;
height: 1.82rem;
line-height: 1.09rem;
border-bottom: 0.02rem solid #333;
text-align: center;
font-size: 1rem;
font-weight: normal;
}
.code-input {
height: 1.09rem;
position: absolute;
outline: none;
color: transparent;
text-shadow: 0 0 0 transparent;
width: 200%;
margin-left: -100%;
border: none;
background: none;
-webkit-appearance: none;
}
}
</style>

简单的密码输入弹框案例完成,详见在线演示