Vue

by leopoldthecuber

HTML

<link rel="stylesheet" href="https://lib.baomitu.com/element-ui/2.4.11/theme-chalk/index.css">
<script src="https://lib.baomitu.com/element-ui/2.4.11/index.js"></script>
<script src="https://lib.baomitu.com/element-ui/2.4.11/locale/zh-CN.js"></script>
<div id="app">
  <el-input type="text" v-model="xxx" @keyup.enter.native="toggle"></el-input>
</div>

Vue

new Vue({
  el: "#app",
  data: {
    xxx: ''
  },
  methods: {
    toggle (e) {
      console.log(e);
      this.validator()
    },
    validator () {
      this.$prompt('请输入用户名', '身份验证', {
        confirmButtonText: '验证',
        cancelButtonText: '取消',
        inputErrorMessage: '用户名格式不正确',
        inputValidator: function (inputValue) {
          if (inputValue === null) inputValue = '';
          if (/[z-z0-9A-Z]{6,20}/gi.test(inputValue)) {
            return true;
          } else {
            return false;
          }
        }
      })
    }
  }
})