I have a intervalID data in vue,I will put setinterval later in method. But i don't know should I initial it and what is type of it?
data() {
return {
intervalID: null as any
};
},
methods: {
getData() {
this.intervalID = setInterval(() => {
this.$http
.get("", {
params: {
source: JSON.stringify(this.query),
source_content_type: "application/json",
},
})
.then((response) => {
##doing something
})
.catch(function (error) {
console.log(error);
});
}, 10000);
},
},
CodePudding user response:
setInterval
returns NodeJS.Timer
. How i know? Well just hover it:
Its just a number, so you can use number
You can read it in the docs: https://www.w3schools.com/jsref/met_win_setinterval.asp
Therefor:
data(): { intervalID: number | null } {
return {
intervalID: null
};
},