No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [Solved] How do I reset a vuex store in Quasar?

    Help
    4
    5
    1544
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rconstantine last edited by rconstantine

      I’d like to reset my store when a user logs out. No data should be saved from one session to another.

      The following post speaks somewhat to what I’m trying to do, but I think vuex is organized a bit differently in Quasar, so I’m not sure how to apply it. (https://github.com/vuejs/vuex/issues/1118)

      In the file tree shown here: https://quasar-framework.org/guide/app-vuex-store.html, can I just add action and mutation files to the same level as index.js?

      Or are you guys resetting your application some other way, particularly at logout?

      Also, what does “if we want some HMR magic for it” mean?

      Thanks - Ryan

      1 Reply Last reply Reply Quote 0
      • M
        Max last edited by

        Quasar usage of vuex is not different. It’s all basic vuejs functionality and resetting the store could be done by any action/mutation clearing/nulling your variables.

        Any specific problems doing that?

        1 Reply Last reply Reply Quote 0
        • P
          panstromek last edited by

          if we want some HMR magic for it is related to hot reload - if you want the store to reload only a single module on changes during development instead of trigger rebuild.

          And yes, you can organize the store however you want - put everything in index.js, or on the same level… it’s up to you. Quasar scaffolds very granular setup at start, but you can definitely reorganize it for your needs. I tend to have just per-file modules, because they are usually pretty small in my projects. In the end store is just a bunch of JS objects and functions that you put inside the Store constructor. There is no restriction on how you organize them.

          You can reset the store with some mutation nulling all variables like Max said. I often use dynamic modules and just register one on login and unregister it on logout. That way I can just throw out all the data easily.

          1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman last edited by metalsadman

            @rconstantine when you refresh page window.location.reload() i think vuex will be reset, or you can use https://github.com/robinvdvleuten/vuex-persistedstate, then clear the LocalStorage/SessionStorage on logout ie. this.$q.localStorage.clear().

            1 Reply Last reply Reply Quote 0
            • R
              rconstantine last edited by

              Thanks for the suggestions. I did end up just making reset actions/mutations for each store module. Seems to work.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post