0

Hello I got The following form where I got a onClick button storing Data in a List. Following on script I call axios and creating methods, So when I press Submit Values are stored in my List. Now my problem is how can I make my Button automatically hit endpoint every 1 minute , so when I refresh my List after 60 minutes , it would contain 60 values inside. And then I want to add first 5 values of list so I find the average values of first 5 minutes

//eslint-disable-next-line no-unused-vars
import axios from 'axios'

export default {
  data() {
    return {
      apiEndPoint: 'https://api.coinbase.com/v2/prices/spot?currency=',
      apiData: [],
      amountList: [],
    }
  },
  created() {
    this.getData(this.currency);
  },
  methods: {
    getShortList(shortListSize) {
      return this.amountList.slice(0, shortListSize);
    },
  },
  getData(currency) {
    axios.get(`${this.apiEndPoint}${currency}`)
      .then((response) => {
        for (let i = 0; i < 59; i++) {
          this.apiData = response.data
          this.amountList.push(response.data.data.amount)
          console.log(response.data.data.amount)
        }
      })
  }
}
<form>
  <label>Enter Currency: <input type="text" v-model="currency"></label>
  <input id="clickMe" type="button" value="Submit" @click="getData(currency)" />
</form>
Rajesh
  • 24,354
  • 5
  • 48
  • 79

1 Answers1

2

maybe you can try to use setInterval() on your getData function for more explanation you can check on this question Vue js triggering a method/function every x seconds

and this a setInterval() usage documentation https://developer.mozilla.org/en-US/docs/Web/API/setInterval

Sunny16
  • 51
  • 3