[Vuejs]-VueJS get request every 20 minutes

0👍

Before your forEach loop, reset the arrays for symbols and price to an empty array, then push the new values to them inside of the forEach loop.

const response = await fetch(
    'https://api2.binance.com/api/v3/ticker/24hr'
  );
const data = await response.json();
const symbols = [];
const price = [];

data.forEach(element => {
  symbols.push(element.symbol);
  price.push(element.lastPrice);
});

this.chartData.symbols = symbols;
this.chartData.price = price;

0👍

Use uniqBy from lodash to remove duplicates.

Not sure the uniqueness would be based on the latest data. For safety, we reverse the array. After filtering the unique date, we reverse the array again in the order it should be.

methods: {
    async fetchApi() {
      const response = await fetch(
        'https://api2.binance.com/api/v3/ticker/24hr'
      );
      const data = await response.json();
      this.chartData = _.uniqBy([...this.data, data].reverse(), 'symbols').reverse()
    }
}

Leave a comment