Home > front end >  Set the setTimeout in vue of ajax callback, how to accurately remove before page destroyed?
Set the setTimeout in vue of ajax callback, how to accurately remove before page destroyed?

Time:11-28


This is to perform as a result, the code is as follows:

CodePudding user response:

Abnormal inside why trigger timer, forced to interrupt an ajax into abnormal for certain, but the jump page again (timer hasn't open how clear? Ajax exception this time to start the timer

CodePudding user response:

Find a solution that directly define a loop, the initialization is set to true, the page before destruction is set to false, the judge in the tt function loop to true to perform, or does not perform, perfect to solve this problem

CodePudding user response:

reference 1/f, three dozen soy sauce response:
why trigger abnormal inside timer, forced to interrupt an ajax into abnormal for certain, but the jump page again (timer hasn't open how clear? Ajax out abnormal this time to start the timer
if not trigger in the abnormal, so when the page request failed once, the follow-up were not request, so also does not conform to product requirements

CodePudding user response:

clearTimeout (enclosing the timer)//every time must define setTimeout before need to empty, otherwise it will create multiple timers, the results you can only cancel this last
This. The timer=setTimeout (3000). This tt,

This. The timer=null//does not make sense

CodePudding user response:

reference 4 floor SCSCMS sunlight response:
clearTimeout (enclosing the timer)//every time must define setTimeout before need to empty, otherwise it will create multiple timers, the results you can only cancel this last
This. The timer=setTimeout (3000). This tt,

This. The timer=null//meaningless


Good, buy is empty that code is only used to test, need to empty also tried before defining setTimeout, use

CodePudding user response:

I also encountered this problem, what I use is to define a Boolean value, to other pages, change the Boolean value to false, through the Boolean value judgment whether to perform settimeout, perfectly solve the problem,

CodePudding user response:

Define the timer in the data, and then in the destruction of life cycle clearTimeout (enclosing the timer)
  • Related