UI效果图如上,先将两个icon切出来备好
<template>
<el-form :model="ruleForm" class="ruleForm">
<el-form-item prop="password">
<el-input class="pswdBox" v-model.trim="ruleForm.password" :type="showPasswordVisible ? 'text' : 'password'" placeholder="请输入登录密码">
<template #suffix>
<el-icon v-if="!showPasswordVisible" class="custom-password-icon" @click="showPasswordVisible = true">
<img :src="getAssetsFile('close_eye.svg')">
</el-icon>
<el-icon v-else class="custom-password-icon" @click="showPasswordVisible = false">
<img :src="getAssetsFile('open_eye.svg')">
</el-icon>
</template>
</el-input>
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
import { ref } from 'vue'
//是否明文显示密码
const showPasswordVisible = ref(false);
</script>
<style lang="scss" scoped>
.pswdBox {
.custom-password-icon {
width: 24px;
height: 24px;
cursor: pointer;
}
}
</style>
实现后效果如下