zoukankan      html  css  js  c++  java
  • vue检查用户名是否重复

    1.vue检查用户名是否重复

    • 前端函数如下,js方法代码无需更改,前端代码逻辑在componentscommonlab_header.vue

    • 只需要修改componentsaxios_apihttp.js中调用的后端地址

    // axios.defaults.baseURL = "http://127.0.0.1:8000/"
    axios.defaults.baseURL = "http://192.168.56.100:8888/"
    
    </template>
     <div>      
         <input
           type="username"
           name="username"
           class="form-control"
           v-model="username"
          @blur="check_username"
          placeholder="请输入用户名">
     </div>
    </template>
    
    <script>
        // 检查用户名 是否使用
       methods: {
        check_username() {
          console.log('判断用户名')
          console.log(this.username == '')
          var reg = new RegExp(/^[a-zA-Z0-9_-]{3,16}$/); //字符串正则表达式 4到14位(字母,数字,下划线,减号)
          if (this.username == '') {
            this.username_message = '用户名不能为空'
            this.username_error = true
            return false
          }
          if (!reg.test(this.username)) {
            this.username_message = '用户名格式不正确'
            this.username_error = true
            return false
          } else {
            // 去后端检查用户名使用数量
            user_count({ type: 'username', data: this.username }).then((res) => {
              console.log(res)
              if (res.data.count > 0) {
                this.username_message = '用户名已存在'
                this.username_error = true
              } else {
                this.username_message = ''
                this.username_error = false
              }
            })
          }
        },
    }
    </script>
    

    2.vue检查手机号是否重复

    <template>
      <div>
        <input
        name="phone"
        class="form-control"
        v-model="phone"
        placeholder="请输入手机号"
        @blur="check_phone">
      </div>
    </template>
    
    <script>
        // 检查手机号是否使用
       methods: {
        check_phone() {
          console.log('检查手机号')
          var reg = new RegExp(/^[1]([3-9])[0-9]{9}$/)
          if (this.phone == '') {
            this.phone_message = '手机号不能为空'
            this.phone_error = true
          }
    
          if (!reg.test(this.phone)) {
            this.phone_message = '手机号格式不正确'
            this.phone_error = true
            return false
          } else {
            // 去后端查用户数量
            user_count({ type: 'phone', data: this.phone }).then((res) => {
              console.log(res)
              if (res.data.count > 0) {
                this.phone_message = '手机号已存在'
                this.phone_error = true
              } else {
                this.phone_message = ''
                this.phone_error = false
              }
            })
          }
        },
    }
    </script>
    
  • 相关阅读:
    ABI与ARM,X86的概念
    数据库升级,如何操作
    shell脚本
    数据库设计范式
    jQuery基础教程
    git clone 失败 fatal: early EOF fatal: the remote end hung up unexpectedly fatal: index-pack failed
    windowserver中PowerShell禁止脚本执行的解决方法
    移动端延迟300ms的原因以及解决方案
    将伪数组转为真正的数组
    cnpm安装时候出现“Unexpected end of JSON input“的解决办法
  • 原文地址:https://www.cnblogs.com/Beginner-Y/p/13781952.html
Copyright © 2011-2022 走看看