Browse Source

vue seTimeout频繁创建不停止问题

luyanan 6 years ago
parent
commit
9de62be473

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

@ -7,8 +7,8 @@
7 7
      </div>
8 8
      <div class="load-box" v-loading="loadprogress">
9 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 12
          </el-col>
13 13
        </el-row>
14 14
      </div>

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

@ -138,7 +138,7 @@ export default {
138 138
      maxShowLength: 300,
139 139
      monitorList: [],
140 140
      monitorCache: [],
141
      jishiTime: null
141
      jishiTime: ''
142 142
    }
143 143
  },
144 144
  computed: {
@ -146,12 +146,11 @@ export default {
146 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 149
  created() {
154 150
    var that = this
151
    if (this.jishiTime) {
152
      clearTimeout(this.jishiTime)
153
    }
155 154
    if (urlParse('id')) {
156 155
      that.bridgeId = urlParse('id')
157 156
      that.bridgeName = urlParse('name')
@ -173,7 +172,8 @@ export default {
173 172
  methods: {
174 173
    updateDataList() {
175 174
      clearTimeout(this.jishiTime)
176
      this.jishiTime = null
175
      this.jishiTime = ''
176
      this.sysTime = ''
177 177
      this.monitorList = []
178 178
      this.monitorCache = []
179 179
      this.getSysTime()
@ -268,14 +268,20 @@ export default {
268 268
            }
269 269
          }
270 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,12 +342,9 @@ export default {
336 342
    }
337 343
  },
338 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 350
</script>