K
K
KeeVeeG2020-07-28 19:16:33
Vue.js
KeeVeeG, 2020-07-28 19:16:33

Why doesn't axios work in SetInterval?

axios request worked, but after adding SetInterval() it stopped sending requests, the request also stopped being displayed in the Network, alert is triggered. What can be wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WapSter, 2020-07-29
@KeeVeeG

The context is lost, use an arrow function.

SaveData(){
        setInterval(() => {
          alert("Save")
          var json_messages = JSON.stringify(this.messages)
          var json_accounts = JSON.stringify(this.accounts)
          axios.get("https://twitchchatbots.top/backend/save_data.php?token="+this.Token()+"&messages="+json_messages+"&accounts="+json_accounts)
        }, 10000)
      },

M
Michael, 2020-07-29
@Nolan81

Are there any errors in the console?
In strict mode, this inside your function will be undefined.
Try changing to an arrow function:
setInterval(() => {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question