方法1:
data () {
return {
timer: null
}
},
mouted(){
this.timer = setInterval (()=>{
console.log(1);
},500)
},
beforeDestroy () {
clearInterval(this.timer)
this.timer = null
},
方法2
mounted () {
const timer
= setInterval(() => {
}, 5000)
this.$once('hook:beforeDestroy', () => {
clearInterval(timer
)
})
},