究极禁用浏览器的自动保存密码提示功能

直接上干货

网上很多文章说使用autoComplete=“off”、使用new-password、动态密码域……现在统统都不行了! 本片文章思路主要是模仿password的输入框

<template>
  <div class="main">
    <h3 style="margin:0 0 30px 0;text-align: center;">登录不保存密码</h3>
    <el-form label-position="left" ref="form" :rules="rules" label-width="70px" :model="form">
      <el-form-item label="用户名" prop="name">
        <el-input placeholder="请输入用户名" v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="pass">
        <div class="pass-box">
          <div class="simulation-pass-box" v-show="!showpass||form.pass.length === 0">
            <span class="remind" v-show="form.pass.length === 0 && !focus"
              >请输入密码</span>
            <span :class="focus?'pass':''" v-show="form.pass.length !== 0">{{ "●●●●●●●●●●●●●●●●●●●●●●●●●●●".substr(0,form.pass.length) }}</span>
          </div>
          <el-input
            v-model="form.pass"
            @keydown.native="keydown"
            @focus="focus = true"
            @blur="focus = false"
            class="formPass"
          ></el-input>
          <i class="el-icon-view" :style="{color:showpass?'#409EFF':'#aaa'}" @click="showpass=!showpass"></i>
        </div>
      </el-form-item>
    </el-form>
    <el-button type="primary" size="medium" plain class="button" @click="submitForm('form')">提交</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: "",
        pass: "",
      },
      focus: false,
      showpass:false,
      rules: {
          name: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
          pass: [{ required: true, message: '请输入密码', trigger: 'blur' }]
    }
    }
  },
  methods: {
    keydown(e) {
      if (e.ctrlKey||e.metaKey) {
        e.preventDefault();
        return false;
      }
    },
     submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
  },
};
</script>

<style scoped lang="scss">
.main {
  width: 300px;
  padding: 40px 30px 80px;
    margin: 100px auto;
    border: 1px solid #ecf5ff;
    border-radius: 5px;
    position: relative;
  .pass-box {
    position: relative;
    .simulation-pass-box {
      width: calc(100% - 4px);
      height: 36px;
      box-sizing: border-box;
      background: #fff;
      position: absolute;
      left: 2px;
      top: 2px;
      padding: 0 15px;
      text-align: left;
      pointer-events: none;
      z-index: 10;
      .remind {
        color: #ccced5;
      }
      .pass {
        &::after {
          content: "丨";
          animation: cursorImg 1s infinite steps(1, start);
          @keyframes cursorImg {
            0%,
            100% {
              opacity: 0;
            }
            50% {
              opacity: 1;
            }
          }
        }
      }
    }
  }
  .button{
    position: absolute;
    right: 30px;
    bottom: 30px;
  }
  .el-icon-view{
    cursor: pointer;
    position: absolute;
    top: 13px;
    right: 10px;
    color: #aaa;
    z-index: 10;
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值