zoukankan      html  css  js  c++  java
  • Vue watch 监听手机号输入完毕后请求数据

    Bac: 需要在用户输入手机号之后,调用后台接口去获取对应该手机号的数据情况

    思路是:监听用户输入手机号,当输入的手机号长度 = 11 的时候,此时再去请求接口。

    在这里监听学习到了两种方式:

    一、watch 监听 计算属性的值

    watch:{
              customerMobile (val, oldval) {
                if (val.length === 11) {
                  this.handleCustomerChange(val)
                }
                // clearTimeout(this.timeout)
                //   this.timeout = setTimeout(() => {
                //     this.handleCustomerChange(val)
                //   }, 500)
              }
            },
     computed : {
              customerMobile () {
                return this.addForm.mobile
              }
        },
      methods: {
              // 输入手机号,客户名称联系人联动
              handleCustomerChange(){
                this.$http.get(`${window.SITE_CONFIG['baseURL']}/presale/presalelist/getDataByMobile`,
                {
                  params:{
                    mobile: this.addForm.mobile
                  }
                })
                .then(data => {
                  if (data.result.code === 0){
                    this.addForm.username = data.result.data.customerName
                    this.addForm.linkman = data.result.data.name
                  } else {
                    this.$message({
                      message: data.result.msg,
                      type: 'error',
                      duration: 1500
                    })
                  }
                })
              }
    }
     

    二、watch直接监听某个对象的属性

    watch:{
              'addForm.mobile' : function(val, oldval){
                  if (val.length === 11) {
                  this.handleCustomerChange(val)
                }
              }
           },
  • 相关阅读:
    Oracle修改表Table所属表空间及Clob、Blob字段的处理
    MyBatis返回多表连接结果
    MyBatis查询结果resultType返回值类型详细介绍
    SpringBoot之分页PageHelper
    Postman简单用法以及转cURL等命令的正确姿势
    postman 巧用cURL
    Spring Boot设置跨域访问
    springboot设置cors跨域请求的两种方式
    @Configuration使用
    @GetMapping和@PostMapping接收参数的格式
  • 原文地址:https://www.cnblogs.com/rabbit-lin0903/p/12665400.html
Copyright © 2011-2022 走看看