首页 > 其他分享 >密码输入框小眼睛的实现

密码输入框小眼睛的实现

时间:2023-10-10 11:12:48浏览次数:25  
标签:String 密码 default text 眼睛 value 输入框 input type

input

先回顾一下input标签常用的属性

常用属性

  • nameinput元素的名字,用于对提交到服务器后的表单数据进行标识
  • placeholder:默认显示文字,一般用来提示用户输入,输入后会被覆盖
  • disabled:禁用
  • checked:选中
  • value:元素的值,,此初始值可以更改,并且在提交表单时,value属性的值会发送给服务器
  1. input type="text"、 "password"、 "hidden"时,定义为输入字段的初始值
  2. input type="button"、 "reset"、 "submit"时,定义为按钮上显示的文本
  3. input type="checkbox"、 "radio"、 "image"时,value的值在提交表单时会发送给服务器
  • typeinput的类型
    常用:
    1. text:默认属性
    2. password:密码框,输入的字符将变成小圆点隐藏
    3. checkbox:复选框,用户可以进行多个选项,其中value属性中的值用来设置用户选中改项目后提交到数据库中的值,拥有相同name属性的复选框为同一组。
    4. radio:单选框,其中value属性中的值用来设置用户选中改项后提交到数据库中的值,拥有相同name属性的单选框为同一组

密码框的实现

要点

  1. 添加睁眼和闭眼的图标
  2. 默认睁眼图标,点击闭眼睁眼切换
  3. 睁眼的同时type类型变为text,闭眼变为password

input.vue组件结构

  • 组件由div大盒子+input框+span放置两个icon组成
    <div class="mio-input">
    	<input class="mio-input__inner"></input>
    	<span class="mio-input__suffix">
    			<mio-icon iconClass="open-eyes"></mio-icon>
    			<mio-icon iconClass="close-eyes"></mio-icon>
    		</span>
    </div>
    

input框需要接收的属性

  1. type:字符串类型,在text和password之间切换
  2. value: 字符串类型,默认为空
  3. placeholder:字符串类型,一般设置为“请输入密码”
  • props中定义:

    props: {
    	type: {
    		type: String,
    		default: 'text'
    	},
    	value: {
    		type: String,
    		default: ''
    	},
    	placeholder: {
    		type: String,
    		default: ''
    	},
    }
    
  • App.vue中使用组件并传值
    使用v-model双向绑定value的值,取名为password,并在该组件定义value的默认值为空

    <mio-input type="password" placeholder="请输入密码" v-model="password">
    </mio-input>
    ···
    data() {
    	return {
    		password: ''
    	}
    }
    
  • input.vue组件中使用props定义的值

    <div class="mio-input">
    	<input
    		class="mio-input__inner"
    		:type="type"
    		:value="value"
    		:placeholder="placeholder"
    	></input>
    	<span class="mio-input__suffix">
    			<mio-icon iconClass="open-eyes"></mio-icon>
    			<mio-icon iconClass="close-eyes"></mio-icon>
    		</span>
    </div>
    

眼睛的切换

因为input组件不单是实现密码框一个类型,所以需要设置一个属性showPassword来判断是否设置为密码框,该值为父组件传来的,需要通过props接收。
眼睛和文本框的类型的切换是同时实现的,type的类型是父组件传过来的,我们不能直接修改父组件传来的值,所以需要设置一个属性passwordVisibe来完成类型的切换,默认值则是true,就是睁眼+类型为text


	<div class="mio-input">
		<input
			class="mio-input__inner"
			:type="type"
			:value="value"
			:placeholder="placeholder"
		></input>

		<!-- 密码专属span,showPassword=true的时候显示 -->
		<span class="mio-input__suffix" v-if="showPassword">
				<mio-icon iconClass="open-eyes"></mio-icon>
				<mio-icon iconClass="close-eyes"></mio-icon>
			</span>
	</div>

	data() {
		return {
			passwordVisibe: true
		}
	},
	props: {
		type: {
			type: String,
			default: 'text'
		},
		value: {
			type: String,
			default: ''
		},
		placeholder: {
			type: String,
			default: ''
		},
		showPassword: {
			type: Boolean,
			default: ''
		}
	}

因为是点击眼睛切换类型,所以在span上设置一个click事件,来控制睁眼闭眼和type类型的切换

	<span class="mio-input__suffix"
            v-if="showPassword"
            @click="handleEyes"
			<!-- passwordVisibe为true显示睁眼的icon,反之显示闭眼的icon -->
			<mio-icon iconClass="open-eyes" v-if="passwordVisible"></mio-icon>
			<mio-icon iconClass="close-eyes" v-if="!passwordVisible"></mio-icon>
      >
	</span>
	···
	methods: {
		handleEyes() {
            this.passwordVisible = !this.passwordVisible
        },
	}

类型的切换通过三元表达式来设置,先判断是否为密码框,再判断passwordVisibe的值

<input
	class="mio-input__inner"
	:type="showPassword ? (passwordVisibe ? 'text' : 'password') : type"
	:value="value"
	:placeholder="placeholder"
>
</input>

代码

<template>
    <div
        class="mio-input"
       :class="[`mio-input--${iconType}`, { 'is-showPassword': showPassword }]">
		<input
			:type="showPassword ? (passwordVisible ? 'text' : 'password') : type"
			class="mio-input__inner"
			:placeholder="placeholder"
			:value="value"
			@input="handleInput"
		>
		    <!-- 密码 -->
			<span
				class="mio-input__suffix"
				v-if="showPassword"
				@click="handleEyes"
			>
				<mio-icon iconClass="open-eyes" v-if="passwordVisible"></mio-icon>
				<mio-icon iconClass="close-eyes" v-if="!passwordVisible"></mio-icon>
			</span>
    </div>
</template>
<script>
	export default {
		name: 'mio-input',
		data() {
			return {
				passwordVisible: true
			}
		},
		props: {
			//文本框类型
			type: {
				type: String,
				default: 'text'
			},
			//文本框默认显示文字
			placeholder: {
				type: String,
				default: ''
			},
			//文本框内容
			value: {
				type: String,
				default: ''
			},
			//密码框
			showPassword: {
				type: Boolean,
				default: false
			},
		},
		methods: {
			handleInput(e) {
				this.$emit('input', e.target.value)
			},
			handleEyes() {
				this.passwordVisible = !this.passwordVisible
				// this.inputType = this.eyes ? 'text' : 'password'
			},
		},
	}
</script>

标签:String,密码,default,text,眼睛,value,输入框,input,type
From: https://www.cnblogs.com/cloud0-0/p/17754138.html

相关文章

  • 案例2 网络设备初始化及Console端口密码认证
    1.华为设备<Huawei><Huawei>system-view[Huawei]user-interfaceconsole0[Huawei-ui-console0]authentication-modepassword[Huawei-ui-console0]setauthenticationpasswordcipherqytang[Huawei-ui-console0][Huawei-ui-console0]quit[Huawei][Huawe......
  • 电脑输入密码后出现 目前没有可用的登录服务器处理登录请求
    电脑输入密码后出现目前没有可用的登录服务器处理登录请求   解决方案:登录时去掉Administrator前面的域名。 ......
  • PostgreSQL添加角色,用户,更新密码,设置权限等配置操作
    创建用户:CREATEUSERqueryWITHPASSWORD'123456';授予用户权限:(1)给予权限:grantgrantselecton表名to用户名;(2)撤消权限:revokerevokeselecton表名from用户名;给用户授予全部表的权限:grantallonalltablesinschemapublictopublic;查看用户权限:select*fr......
  • 联想亚运“零故障”的全栈智能密码
    作者|曾响铃文| 响铃说1912年,电子计时器首次应用,1936年,体育赛事首次在电视上播出,1972年计算机首次进入人类赛事,1996年互联网技术大范围应用,随后3G网络、3D技术、VR技术……以奥运会为代表,人类赛事的发展就是一部技术发展史诗。刚刚结束的杭州亚运会,“智能”成为关键词,这部史诗......
  • 商用密码产品
    商用密码产品一、28类密码产品商用密码产品认证目录(第一批)智能密码钥匙智能IC卡POS密码应用系统ATM密码应用系统多功能密码应用互联网终端PCI-E/PCI密码卡IPsecVPN产品/安全网关SSLVPN产品/安全网关安全认证网关密码键盘金融数据密码机服务器密码机签名验签服务器......
  • 密码——古典密码学介绍
    古典密码学密码学的首要目的是隐藏信息的涵义,而并不是隐藏信息的存在,这是密码学与隐写术的一个重要区别。 基本密码键盘布局加密通常都是给出一堆无意义的字符,但是将这些字符按照在键盘上的布局比划一下,就可以根据形状拼出相应字符。都是圈的情况下,可能是圈起来的那个字......
  • 记一次某大型会议官网任意密码重置漏洞挖掘(CNVD-2023-41929)
    记录一次本人CNVD漏洞挖掘的过程,此漏洞已被分配编号:CNVD-2023-41929引言本文记录了一次对某大型会议官网任意密码重置漏洞的挖掘,漏洞挖掘时该会议处于即将召开的状态,参会人员来自国际和国内。漏洞挖掘通过信息收集和测试发现存在一个管理后台,且有重置密码接口,但需要一个nonce......
  • mysql8.x root 密码忘记了如何重置
    网上也有很多关于重置密码的,由于版本的问题,很多无法正常重置密码。因此在这里将重置密码的方法进行整理下,方便以后参考:一、免密登录mysql1、停止mysql服务cmd窗口输入netstopmysql 2、设置免密登录mysqld--console--skip-grant-tables--shared-memory 3、另开一个cm......
  • 密码协议学习笔记(8.16):几种特殊的秘密分享体系
    已知两个秘密的碎片,计算秘密的乘积的碎片:已知两个秘密$\alpha_0,\beta_0$分别实现了门限值为$t$的分享记$$f_{\alpha}(x)=\alpha_0+\alpha_1x+\cdots+\alpha_{t-1}x^{t-1}$$$$f_{\beta}(x)=\beta_0+\beta_1x+\cdots+\beta_{t-1}x^{t-1}$$秘密碎片为$$A_1=f_{\alpha}(1),A_2=......
  • 密码协议学习笔记(8.15):知识证据详解
    在开始前,先回顾以下的知识点:离散对数问题(DiscretelogarithmProblem,DLP)难解性猜想:给定以大素数$p$为阶的循环群$G$,$g,h\inG$是两个生成元(在素数阶群上等价于非恒等元),求解$t$,使得$h^t=g$在计算上是不可行的.Diffie-Hellman的计算难解性(ComputationalDiffie-Hellm......