search

Home  >  Q&A  >  body text

What is the difference between vuex and localstorage for storing data

What is the difference between vuex and localstorage for storing data

怪我咯怪我咯2789 days ago831

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-05-18 11:02:30

    vuex stores the state, which represents the data corresponding to the view, and the storage location is in the memory;

    Localstorage is an interface provided by the browser that allows you to save files and disks on your computer. Of course, you can also save the status locally!

    reply
    0
  • PHPz

    PHPz2017-05-18 11:02:30

    They are completely two things. vuex is the state management mechanism in Vue, which facilitates communication between components; and localstorage is local storage, which is a method of storing data in the browser. It is generally used when transferring data across pages.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-18 11:02:30

    They are completely different things. Vuex is used for state management, which is the type of component data sharing. Data changes in one component will be mapped to other components that use this data. Let’s talk about localstorage, which is a simpler data storage method provided by H5. Previously, cookies were used to store data, but the amount of data stored in cookies was too small, and the interface was cumbersome. Localstorage data can have a limit of 5M, which is quite large, and the API is quite simple, easy to remember and easy to use. I believe it will become mainstream in the future.

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-18 11:02:30

    xsf——1991 has already said it quite well. I would like to add that if your dispatch trigger vuex is not written in the current route and refresh the page, the data previously stored in vuex will be initialized and the data in vuex will be lost.

    reply
    0
  • Cancelreply