Answers for "how to set loop in vuex actions"

0

how to set loop in vuex actions

async GET_PRODUCTS({commit}, {cat}) {
    let products = []
    for (let i = 0; true; i++) { // <--- loop forever
        let arr = await axios.get(
          `https://example.com/api/get-items.php`, {
            params: {
              cat,
              token: "0e94e09856a22496613b325473b7de8cb0a",
              p: i
            }
          }
        )
      products = products.concat(arr.data) // <--- concatenate new array to the old one
      commit('SET_PRODUCTS', products)
      if (arr.data.length < 100) break // <--- exit the cycle
    }
    console.log(products);
    return products
  },
Posted by: Guest on July-30-2021

Code answers related to "how to set loop in vuex actions"

Browse Popular Code Answers by Language