账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    js 同一个组件被调用2次,但是setTimeout只执行一次
    43
    0

    我的一个父组件,导入了同一个子组件2次(传入的参数不一样,所以子组件的值也不一样)。
    初始化的时候,两个子组件都进入下面的this.search()方法,具体到 delay = setTimeout(function () {
    这一行。但是
    let params = {type: $this.type, supplierService: $this.supplierService, toS: $this.toS}
    这一样只有一个组件能进入。这是为什么啊?怎么解决两个子组件都能取查后台?

    onChangeHandler (val) {
            debugger
            if (!this.init) {
              this.search()
              return
            }
            let customer = this.selectCustomer(val)
            this.$emit('input', val)
            // console.log('on-change')
            this.$emit('on-change', customer, this.index)
          },
          
          
      search (val) {
        if (this.allOptions && this.init) {
          return
        }
        this.loading = true
        if (delay) {
          clearTimeout(delay)
        }
        let $this = this
        delay = setTimeout(function () {
          let params = {type: $this.type, supplierService: $this.supplierService, toS: $this.toS}
          if (!$this.allOptions && val) {
            params.keyword = val
          }
          if ($this.allOptions) {
            params.pageSize = 9999 // 查询全部数据,用于车队这种多选的场景
          } else {
            params.pageSize = $this.pageSize
          }
          if ($this.foreign === true) {
            params.foreign = 1
          } else if ($this.foreign === false) {
            params.foreign = 0
          }
          MosService.select(params).then(r => {
            $this.loading = false
            if (r.success) {
              $this.customerOptions = r.content.data.value
              $this.init = true
            }
          })
        }, 300)
      },
    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • ζ丿念旧 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部