Home > Blockchain >  what is type of unknown initial variable in vue 3
what is type of unknown initial variable in vue 3

Time:05-17

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:

enter image description here

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
    };
  },
  • Related