1. 问题场景
在密码登陆时,有显示和隐藏密码的功能,实现方式很简单,直接对输入 input 的 type 进行 password 和 text 值进行切换,就可以实现密码的显示和隐藏。
2. 实现代码
- 通过修改 input 的 type 值实现密码的显示和隐藏。
- 密码的显示和隐藏控制图标也是通过 type 值进行判断显示对应图标。
import { View, Input, Image } from '@tarojs/components';
import { useAsyncState } from '@utils/event';
import licon from '@utils/icon/licon';
import api from '@utils/api';
import './index.scss';
const RuiPasswordInput = (props) => {
let {
placeholder,
value = '',
type = 'password'
} = props;
let [new_value, setnew_value] = useAsyncState(value);
let [new_type, setnew_type] = useAsyncState(type);
return <View className='rui-password-input-temp-content rui-fg rui-flex-ac'>
<View classNa
本文介绍了在Taro和React.js开发的微信小程序中,遇到iOS真机上Input密码框切换type时内容丢失的问题。通过分析原因并提出解决方案,建议使用两个Input组件分别对应password和text类型,避免因type切换导致的value丢失问题。
订阅专栏 解锁全文
489

被折叠的 条评论
为什么被折叠?



