[ad_1]
Hi Everyone I am trying to delete a "product" the product does get deleted from the database, in my VuexStore i have a array of products so when i want to delete on i would like to splice that list, so what i have done is the following
This is the action that gets dispatched, and it is working, it does the delete
removeProduct( commit , payload) {
commit(REMOVE_PRODUCT)
axios.delete(`$API_BASE/product/$payload`, payload).then(response =>
console.debug('response', response.data)
commit(REMOVE_PRODUCT_SUCCESS, response.data)
)
Here is my mutation, i want to get the list of products from the store and check the index of the product where the product id is equal to the payload
[REMOVE_PRODUCT_SUCCESS]: (state, payload) =>
state.showLoader = false
const index = state.products.indexOf(product => product.id === payload)
state.products.splice(index, 1)
,
if i console log this state.products.indexOf(product => product.id) i get -1
the payload is an object at the moment, but when i change that to the id of that object this state.products.indexOf(product => product.id) is still -1
Please help how can i get the index of the product i want to delete from the array of products and splice that product from the list
[ad_2]
لینک منبع