Browse Source

vue seTimeout频繁创建不停止问题

luyanan 6 years ago
parent
commit
9de62be473

+ 2 - 2
src/views/bridgesConsole/bridgeDanger/dangerDetail.vue

7
      </div>
7
      </div>
8
      <div class="load-box" v-loading="loadprogress">
8
      <div class="load-box" v-loading="loadprogress">
9
        <el-row class="line-chart-box">
9
        <el-row class="line-chart-box">
10
          <el-col :xs="24" :sm="24" :lg="24" v-for="(item, index) in alarmShowList" :key="item.index">
11
            <lineChart :chartData="item" :lineColor="index" :historyM="historyM"></lineChart>
10
          <el-col :xs="24" :sm="24" :lg="24" v-for="item in alarmShowList" :key="item.index">
11
            <lineChart :chartData="item" :historyM="historyM"></lineChart>
12
          </el-col>
12
          </el-col>
13
        </el-row>
13
        </el-row>
14
      </div>
14
      </div>

+ 22 - 19
src/views/bridgesConsole/bridgeDetail/index.vue

138
      maxShowLength: 300,
138
      maxShowLength: 300,
139
      monitorList: [],
139
      monitorList: [],
140
      monitorCache: [],
140
      monitorCache: [],
141
      jishiTime: null
141
      jishiTime: ''
142
    }
142
    }
143
  },
143
  },
144
  computed: {
144
  computed: {
146
      return this.monitorList.slice((this.currentNo - 1) * this.currentSize, this.currentNo * this.currentSize)
146
      return this.monitorList.slice((this.currentNo - 1) * this.currentSize, this.currentNo * this.currentSize)
147
    }
147
    }
148
  },
148
  },
149
  beforeCreate() {
150
    clearTimeout(this.jishiTime)
151
    this.jishiTime = null
152
  },
153
  created() {
149
  created() {
154
    var that = this
150
    var that = this
151
    if (this.jishiTime) {
152
      clearTimeout(this.jishiTime)
153
    }
155
    if (urlParse('id')) {
154
    if (urlParse('id')) {
156
      that.bridgeId = urlParse('id')
155
      that.bridgeId = urlParse('id')
157
      that.bridgeName = urlParse('name')
156
      that.bridgeName = urlParse('name')
173
  methods: {
172
  methods: {
174
    updateDataList() {
173
    updateDataList() {
175
      clearTimeout(this.jishiTime)
174
      clearTimeout(this.jishiTime)
176
      this.jishiTime = null
175
      this.jishiTime = ''
176
      this.sysTime = ''
177
      this.monitorList = []
177
      this.monitorList = []
178
      this.monitorCache = []
178
      this.monitorCache = []
179
      this.getSysTime()
179
      this.getSysTime()
268
            }
268
            }
269
          }
269
          }
270
          that.monitorList = mList
270
          that.monitorList = mList
271
          var st = new Date().getTime() + that.eastEightDistrict - that.localTimeiv
272
          var iv = that.sysTime - st
273
          if (iv < 0) {
274
            iv = 1
271
          if (that && !that._isDestroyed) {
272
            var st = new Date().getTime() + that.eastEightDistrict - that.localTimeiv
273
            var iv = that.sysTime - st
274
            if (iv < 0) {
275
              iv = 1
276
            }
277
            that.jishiTime = setTimeout(function() {
278
              if (that && !that._isDestroyed) {
279
                that.getTimingMonitor()
280
              }
281
            }, iv)
282
          } else {
283
            that.jishiTime = ''
275
          }
284
          }
276
          that.jishiTime = setTimeout(() => {
277
            that.getTimingMonitor()
278
          }, iv)
279
        }
285
        }
280
      })
286
      })
281
    },
287
    },
336
    }
342
    }
337
  },
343
  },
338
  beforeDestroy() {
344
  beforeDestroy() {
339
    clearTimeout(this.jishiTime)
340
    this.jishiTime = null
341
  },
342
  destroyed() {
343
    clearTimeout(this.jishiTime)
344
    this.jishiTime = null
345
    this.$once('hook:beforeDestroy', () => {
346
      clearInterval(this.jishiTime)
347
    })
345
  }
348
  }
346
}
349
}
347
</script>
350
</script>