Answer the question
In order to leave comments, you need to log in
Why setTimeout here?
Greetings.
I'm looking at this official example of a shopping cart using vuex, and I don't understand why they use setTimeout?
Here is the code:
shop.js
const _products = [
{"id": 1, "title": "iPad 4 Mini", "price": 500.01, "inventory": 2},
{"id": 2, "title": "H&M T-Shirt White", "price": 10.99, "inventory": 10},
{"id": 3, "title": "Charli XCX - Sucker CD", "price": 19.99, "inventory": 5}
]
export default {
getProducts (cb) {
setTimeout(() => cb(_products), 100) // <--------- Вот этот
}
}
import shop from '../../api/shop'
// initial state
const state = () => ({
all: []
})
// getters
const getters = {}
// actions
const actions = {
getAllProducts ({ commit }) {
shop.getProducts(products => {
commit('setProducts', products)
})
}
}
export default {
// ...
created () {
this.$store.dispatch('products/getAllProducts')
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question