S
S
SM_ST2021-02-24 23:55:13
Vue.js
SM_ST, 2021-02-24 23:55:13

How to pull cart items from localStorage to store in NuxtJs when opening website?

Front part on Nuxt.js api on Laravel
when adding goods to the cart, I first add it to store state.cart and immediately save the cart to LocalStorage

state.cart.push(product)
this.commit('SAVE_CART_TO_LOCALSTORAGE')


SAVE_CART_TO_LOCALSTORAGE (state) {
    window.localStorage.setItem('cart', JSON.stringify(state.cart))
  },


how to pull out the basket from localStorage when opening the site and write it to the store?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dark_king_13, 2021-02-26
@dark_king_13

https://www.npmjs.com/package/nuxt-vuex-localstorage
Synchronizes LocalStorage and Vuex

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question