常用定时器:
setInterval(function(){}, milliseconds)——会不停的调用函数
setTimeout(function(){}, milliseconds)——只执行函数一次
setTimeout是自带清除定时器:
<script>
export default {
data() {
return {
timer:null, //定时器
}
},
mounted(){
this.profileInfo(),
this.timer = setInterval(() => {
setTimeout(this.profileInfo, 0)
}, 30000)
},
methods: {
this.profileInfo();
},
beforeDestroy(){
clearInterval(this.timer);
this.timer = null;
}
}
</script>