<template>
<div>
<h3>延时器setInterval和setTimeout</h3>
<h3>
setInterval,是每间隔几秒就会执行里面的方法,代码,直到clearInterval清除以后
</h3>
<h3>
setTimeout,延时执行,本来要执行某个方法,某一行代码,但是延迟了3秒以后才执行。
</h3>
</div>
</template>
<script>
export default {
data() {
return {
number: 1,
};
},
computed: {},
methods: {},
mounted() {
//每隔一秒就会执行这个动作,直到清除动作clearInterval(timer1)执行以后
let timer1 = setInterval(() => {
console.log("setInterval", this.number);
if (this.number == 6) {
clearInterval(timer1);
} else {
this.number += 1;
}
}, 1000);
//间隔6秒以后才执行这个动作
setTimeout(() => {
console.log("setTimeout");
}, 6000);
},
};
</script>
<style scoped lang="scss"></style>