小程序带输入框的弹窗

老规矩,直接上代码

    <block wx:if="{{isShowConfirm}}">
      <view class='toast-box'>
        <view class='toastbg'></view>
        <view class='showToast'>
            <view class='toast-title'>
                <text>确认支付</text>
            </view>
            <view class='toast-main'>
                <view class='toast-input'>
                    <input type='password' placeholder='输入支付密码' bindinput='setValue' data-name='stuEidtName'></input>
                </view>
            </view>
            <view class='toast-button'>
                <view class='button1'>
                    <button catchtap='cancel'>取消</button>
                </view>
                <view class='button2'>
                    <button data-url="../allOrder/allOrder" catchtap='confirmAcceptance'>确定</button>
                </view>
            </view>
        </view>
    </view>
  </block>
.toast-box {
    width: 100%;
    height: 100%;
    opacity: 1;
    position: fixed;
    top: 0px;
    left: 0px;
}
 
 
.toastbg {
    opacity: 0.2;
    background-color: black;
    position: absolute;
    width: 100%;
    min-height: 100vh;
}
 
.showToast {
    position: absolute;
    opacity: 1;
    width: 70%;
    margin-left: 15%;
    margin-top: 40%;
}
 
.toast-title {
    padding-left: 5%;
    background-color: #2196f3;
    color: white;
    padding-top: 2vh;
    padding-bottom: 2vh;
    border-top-right-radius: 16rpx;
    border-top-left-radius: 16rpx;
}
 
.toast-main {
    padding-top: 2vh;
    padding-bottom: 2vh;
    background-color: white;
    text-align: center;
}
 
.toast-input {
    margin-left: 5%;
    margin-right: 5%;
    border: 1px solid #ddd;
    padding-left: 2vh;
    padding-right: 2vh;
    padding-top: 1vh;
    padding-bottom: 1vh;
}
 
.toast-button {
    display: flex;
}
 
.button1 {
    width: 50%;
}
 
.button2 {
    width: 50%;
}
 
.button1 button {
    width: 100%;
    background-color: white;
    color: red;
    border-radius: 0px;
    border-bottom-left-radius: 16rpx;
}
 
.button2 button{
    width: 100%;
    background-color: white;
    color: black;
    border-radius: 0px;
    border-bottom-right-radius: 16rpx;
}

顺便贴一下js好了,不关js事, 完全就是为了直接复制不会报错

  //data
  isShowConfirm:false        

  setValue: function (e) {
    this.setData({
      walletPsd: e.detail.value
    })
  },
  cancel: function () {
    var that = this
    that.setData({
      isShowConfirm: false,
    })
  },
  confirmAcceptance:function(){
    var that = this
    that.setData({
      isShowConfirm: false,
    })
  },

 

### 实现输入框弹窗组件 为了实现在 UniApp 中开发微信小程序输入框弹窗组件,可以采用 `uni-popup` 组件配合 `<input>` 标签完成。此方法不仅适用于 H5 平台,同样可以在微信小程序环境中良好运作。 #### 使用 uni-popup 和 Input 组件构建弹窗输入框 通过组合使用 `uni-popup` 及其内部放置的 `Input` 控件,能够创建一个具备输入能力的对话框。下面是一个简单的例子展示如何实现这一功能: ```html <template> <view> <!-- 触发按钮 --> <button type="primary" @click="openPopup">打开弹窗</button> <!-- 弹窗部分 --> <uni-popup ref="popup" type="dialog"> <uni-popup-dialog title="请输入内容" mode="buffer" before-close="true" :value="inputValue" placeholder="这里输入..." @confirm="handleConfirm"></uni-popup-dialog> </uni-popup> </view> </template> <script> export default { data() { return { inputValue: '' }; }, methods: { openPopup() { this.$refs.popup.open(); }, handleConfirm(value) { console.log('确认:', value); // 处理逻辑... this.inputValue = ''; this.$refs.popup.close(); } } }; </script> ``` 这段代码展示了怎样定义并操作一个可交互式的弹窗界面[^1]。当用户点击“打开弹窗”的按钮时会触发 `openPopup()` 方法显示弹窗;而一旦按下确认键,则调用 `handleConfirm()` 函数处理用户的输入数据,并关闭当前窗口。 对于可能出现的问题如输入框占位符(placeholder)或实际值(value)在某些情况下发生抖动的现象,这可能是由于弹出层自过渡效果所致。如果遇到此类情况,建议调整或禁用相关动画设置以解决问题[^3]。 另外需要注意的是,在多输入框场景下可能会面临焦点丢失的情况。为了避免这个问题,应该确保每次只允许单个输入框获得焦点,并合理管理各个控件之间的事件监听器[^4]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值