ios 端input框在uni-app中开会切换需要二次点击才能聚焦的安卓是好的

ios 端input框在uni-app中开会切换需要二次点击才能聚焦的安卓是好的

开发环境 版本号 项目创建方式
Windows 24H2 HBuilderX

示例代码:

<template>  
<view class="page-container">  
<common-head :isReturn='true' :title="pageTitle">  
</common-head>  
<view class="content">  
<view class="operation-card">  
<view class="card-title">  
设置密码  
</view>  
<view class="card-item">  
<view class="left">  
<text>新密码</text>  
</view>  
<view class="center">  
<input type="text" maxlength="16" :password="NPWD" class="s-input"  
placeholder="请输入新密码" v-model="passwordVo.new_password"  
/>  
</view>  
<view class="right">  
<uni-icons class="right-icon" color="#999999" :size="24"  
type="NPWD?'eye-slash':'eye'" [@click](/user/click)="changePassword('NPWD')" />
</view>
</view>
<view class="card-item">
    <view class="left">
        <text>确认密码</text>
    </view>
    <view class="center">
        <input type="text" maxlength="16" :password="CPWD" class="s-input"
            placeholder="请输入确认密码" v-model="passwordVo.confirm_password"
             />
    </view>
    <view class="right">
        <uni-icons class="right-icon" color="#999999" :size="24"  
type="CPWD?'eye-slash':'eye'" [@click](/user/click)="changePassword('CPWD')" />
    </view>
</view>
</view>
</view>
<view class="submit-box">
    <view [@click](/user/click)="confirm" class="submit-btn" :class="{'active':canLogin}">
提交
    </view>
</view>
</view>
</template>  

<script>
import service from '@/service';
import {
regexPassword
} from '@/utils/formRegex.js';
export default {
components: {},
computed: {
// 登录按钮是否高亮
canLogin() {
if (this.passwordVo.new_password && this.passwordVo.confirm_password) {
return true;
} else {
return false;
}
}
},
data() {
return {
pageTitle: '修改密码',
passwordVo: {
new_password: '',
confirm_password: '',
},
NPWD: true,
CPWD: true,
};
},
methods: {
// 密码框切换
changePassword(val) {
this[val] = !this[val];
},
newpasswordInput({
detail: {
value
}
})
{
// if (regexPassword(value)) {
//  console.log('密码验证成功');
// } else {
//  uni.showToast({
//      icon: 'none',
//      title: '密码至少8个字符,且包含大小写英文字母及数字',
//  });
// }
},
confirm() {
if (this.passwordVo.new_password === '') {
uni.showToast({
icon: 'none',
title: '新密码不能为空',
});
return;
}
if (this.passwordVo.confirm_password === '') {
uni.showToast({
icon: 'none',
title: '确认密码不能为空',
});
return;
}
if (this.passwordVo.new_password != this.passwordVo.confirm_password) {
uni.showToast({
icon: 'none',
title: '两次输入的密码不一致',
});
return;
} else if (!regexPassword(this.passwordVo.new_password)) {
uni.showToast({
icon: 'none',
title: '密码至少8个字符,且包含大小写英文字母及数字',
});
return;
} else if (!regexPassword(this.passwordVo.confirm_password)) {
uni.showToast({
icon: 'none',
title: '密码至少8个字符,且包含大小写英文字母及数字',
});
return;
} else {
this.senNet();
}

},
senNet() {
let obj = {
password: this.passwordVo.new_password
};
this.$http.setPassword(obj).then((res) => {
if (res.code === '000000') {
uni.showToast({
icon: 'none',
title: '密码设置成功',
mask: true,
duration: 2000
});
setTimeout(() => {
uni.reLaunch({
url: '/pages/my/index'
})
}, 2000);
}
}).finally(() => {
uni.hideLoading({
noConflict: true
});
});
},
};
</script>  

<style lang="scss" scoped>
.page-container {
background: #F7F7F7;
}

.content {
.operation-card {
background: #fff;
margin: 20rpx 20rpx 0;
border-radius: 16rpx;
overflow: hidden;

.card-title {
font-weight: 500;
font-size: 32rpx;
color: #000000;
line-height: 28rpx;
margin: 40rpx 30rpx 34rpx;
}

.card-item {
height: 112rpx;
display: flex;
align-items: center;
border-bottom: 2rpx solid #F7F7F7;
margin: 0 32rpx;
padding: 32rpx 0;
box-sizing: border-box;
border-radius: 16rpx;
overflow: hidden;

.left {
width: 160rpx;
}

.center {
flex: 1;
display: flex;
align-items: center;

.s-input {
flex: 1;
height: 112rpx;
}
}

.right {
width: 48rpx;
padding: 20rpx;
margin-left: 20rpx;

.right-icon {
height: 100%;
display: flex;
align-items: center;
// padding: 0 10rpx;
}
}
}

.card-item:last-child {
border-bottom: none;
}
}
}

.submit-box {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: #fff;
padding: 28rpx 32rpx 68rpx;
border-radius: 32rpx 32rpx 0px 0px;
overflow: hidden;
box-sizing: border-box;

.submit-btn {
width: 100%;
height: 100rpx;
background: #C4D6FF;
border-radius: 16rpx;
font-weight: 600;
overflow: hidden;
font-size: 36rpx;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
}

.submit-btn.active {
background: #3974FE;
}
}
</style>

更多关于ios 端input框在uni-app中开会切换需要二次点击才能聚焦的安卓是好的的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

你好,可以测试一下原生的微信小程序输入框有在ios微信小程序上有此问题吗?

更多关于ios 端input框在uni-app中开会切换需要二次点击才能聚焦的安卓是好的的实战教程也可以访问 https://www.itying.com/category-93-b0.html


日了,原生也有

tm,把锅甩给腾讯,老板今天就要

回复 1***@qq.com: 这样得去微信社区反馈一下了

这是一个常见的iOS兼容性问题。在iOS系统中,input元素的点击事件处理机制与Android不同。

问题原因: iOS的安全机制导致点击input区域时,系统需要确认用户意图,特别是当input被其他可点击元素包围时。

解决方案:

  1. 给input添加明确的点击事件:
<input 
  type="text" 
  maxlength="16" 
  :password="NPWD" 
  class="s-input"
  placeholder="请输入新密码" 
  v-model="passwordVo.new_password"
  @click="handleInputClick"
/>
  1. 在methods中添加聚焦方法:
methods: {
  handleInputClick(e) {
    // 强制聚焦
    e.currentTarget.focus()
  },
  // ...其他方法
}
  1. 或者使用CSS解决方案:
.s-input {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
回到顶部