uniapp仿微信支付密码输入框
时间: 2023-12-26 07:04:51 浏览: 174
以下是使用uniapp实现仿微信支付密码输入框的示例代码:
```html
<template>
<view class="container">
<view class="input-box">
<view
v-for="(item, index) in inputList"
:key="index"
class="input-item"
:class="{ 'input-item-active': index === currentIndex }"
>
<view class="input-dot" v-show="item !== ''"></view>
</view>
</view>
<view class="keyboard">
<view class="keyboard-row" v-for="row in keyboard" :key="row">
<view
class="keyboard-item"
v-for="key in row"
:key="key"
@click="handleKeyClick(key)"
>
{{ key }}
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
inputList: ['', '', '', '', '', ''], // 输入框列表
currentIndex: 0, // 当前输入框索引
keyboard: [
['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
['', '0', '删除']
] // 键盘布局
};
},
methods: {
handleKeyClick(key) {
if (key === '删除') {
if (this.currentIndex > 0) {
this.currentIndex--;
this.inputList[this.currentIndex] = '';
}
} else {
if (this.currentIndex < this.inputList.length) {
this.inputList[this.currentIndex] = key;
this.currentIndex++;
}
}
}
}
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.input-box {
display: flex;
justify-content: space-between;
width: 300rpx;
height: 50rpx;
border: 1rpx solid #ccc;
border-radius: 4rpx;
overflow: hidden;
}
.input-item {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
font-size: 24rpx;
color: #333;
}
.input-item-active {
background-color: #f5f5f5;
}
.input-dot {
width: 10rpx;
height: 10rpx;
border-radius: 50%;
background-color: #333;
}
.keyboard {
margin-top: 20rpx;
}
.keyboard-row {
display: flex;
justify-content: space-between;
margin-bottom: 10rpx;
}
.keyboard-item {
display: flex;
align-items: center;
justify-content: center;
width: 100rpx;
height: 100rpx;
border: 1rpx solid #ccc;
border-radius: 4rpx;
font-size: 32rpx;
color: #333;
}
</style>
```
这段代码实现了一个简单的支付密码输入框,包括自定义的输入框样式和键盘布局。用户可以点击键盘上的数字输入密码,点击删除按钮可以删除已输入的密码。输入的密码会在输入框中显示为黑色圆点。
阅读全文