Vue input密码输入框自定义密码眼睛icon

本文介绍如何在Vue项目中根据设计稿自定义密码输入框的眼睛图标,通过实现点击切换显示/隐藏密码的功能。使用饿了么UI组件库为基础,详细讲解数据绑定和方法实现。
摘要由CSDN通过智能技术生成

我们用的饿了么UI组件库里,密码输入框的icon是固定不变的,如下所示:
在这里插入图片描述
点击"眼睛"这个icon不变,现在需求是UI给的设计稿里,密码输入框的"眼睛"有如下两种:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
代码如下:

  <el-input
              :</
  • 11
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想在 nvue 中实现密码输入框的小眼睛效果,可以使用 uni-icons 中的图标库,其中有“eye”和“eye-off”两个图标,分别表示显示密码和隐藏密码。具体实现步骤如下: 1. 在 nvue 页面中引入 uni-icons 组件库 ```html <template> <view> <uni-icons></uni-icons> </view> </template> <script> import uniIcons from '@/uni-icons/uni-icons.vue' export default { components: { uniIcons } } </script> ``` 2. 在密码输入框旁边添加一个小眼睛图标,并设置点击事件 ```html <template> <view> <input type="password" v-model="password" /> <uni-icons class="eye-icon" :name="eyeIcon" @click="togglePassword"></uni-icons> </view> </template> <script> import uniIcons from '@/uni-icons/uni-icons.vue' export default { components: { uniIcons }, data() { return { password: '', showPassword: false } }, computed: { eyeIcon() { return this.showPassword ? 'eye' : 'eye-off' } }, methods: { togglePassword() { this.showPassword = !this.showPassword } } } </script> <style scoped> .eye-icon { position: absolute; right: 10px; top: 10px; font-size: 26px; color: #999; cursor: pointer; } </style> ``` 3. 在点击事件中切换密码输入框input type 属性 ```html <template> <view> <input :type="showPassword ? 'text' : 'password'" v-model="password" /> <uni-icons class="eye-icon" :name="eyeIcon" @click="togglePassword"></uni-icons> </view> </template> <script> import uniIcons from '@/uni-icons/uni-icons.vue' export default { components: { uniIcons }, data() { return { password: '', showPassword: false } }, computed: { eyeIcon() { return this.showPassword ? 'eye' : 'eye-off' } }, methods: { togglePassword() { this.showPassword = !this.showPassword } } } </script> <style scoped> .eye-icon { position: absolute; right: 10px; top: 10px; font-size: 26px; color: #999; cursor: pointer; } </style> ``` 通过上述步骤,你就可以在 nvue 中实现密码输入框的小眼睛效果了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值