vue 点击空白区域隐藏div

在vue的mounted中写,在vue中,jq的this并没有指向当前的data,需const _this = this 改变this指向

   const _this = this 
    $(document).click(function(e) {
      console.log('e', e)
      if (_this.debug === 0) { // 如果当前是显示的,则将标志位设置为1
        console.log('0')
        _this.debug = 1
        return
      }
      if (_this.debug === 1) { // 当目前为隐藏时或者已经在展示状态时判断
        // console.log('1')
        // console.log('1', (e.target).parents('.content'))
        // console.log('133', e.target)
        if ($(e.target).parents('.content').length === 0) { // 如果未点击对应位置则隐藏
          // _this.is_select_show = false
        }
      }
    })

2,在“点击”按钮出现的div的事件中

    openAddress() {
      this.is_select_show = !this.is_select_show
      if (this.is_select_show) {
        this.debug = 0 // 保存当前为展示的状态
      } else {
        this.debug = 1
      }
    },

猜你喜欢

转载自www.cnblogs.com/wangliko/p/10917479.html