效果图:
在这里插入图片描述
双向绑定 inputEmail,如果没使用element框架,把有 el- 的自己替换回来

          <el-input v-model="inputEmail" placeholder="请输入邮箱账号" clearable prefix-icon="el-icon-user"></el-input>
          <div class="hintBox">
            <div @click="setInput(mail)" class="hintItem"  v-for="mail in emails" :key="mail">{{mail}}</div>
          </div>
export default {
  name: 'login',
  data () {
    return {
      inputEmail: ''
    }
  },
  methods: {
    // 点击该邮箱后缀是补全文本框
    setInput (mail) {
      this.inputEmail = mail
    }
  },
  computed: {
    emails () {
      // 如果inputEmail中没有任何东西,则不处理
      if (!this.inputEmail) return []
      // 考虑到用户自己要输@符号,如果@符号首次出现的位置大于等于第零个位置时,则不处理
      if (this.inputEmail.indexOf('@') > -1) return []
      return [
        this.inputEmail + '@163.com',
        this.inputEmail + '@126.com',
        this.inputEmail + '@0355.net',
        this.inputEmail + '@263.net',
        this.inputEmail + '@3721.net',
        this.inputEmail + '@qq.com',
        this.inputEmail + '@yahoo.com',
        this.inputEmail + '@gmail.com',
        this.inputEmail + '@msn.com',
        this.inputEmail + '@hotmail.com',
        this.inputEmail + '@aol.com',
        this.inputEmail + '@ask.com',
        this.inputEmail + '@live.com',
        this.inputEmail + '@yeah.net'
      ]
    }
  }
}

简单的css样式,仅供参考

  .hintBox {
    width: 100%;
    max-height: 120px;
    overflow-y:scroll;
    overflow-x: auto;
    position: absolute;
    z-index: 999;
    background-color: #fff;
  }
  .hintItem {
    margin-top: 2px;
    cursor:pointer;
    margin-left: 45px;
    font-size: 13px;
    color: #898989;
  }
Logo

前往低代码交流专区

更多推荐