Search code examples
vue.jsvuexnuxt.js

How can I access the vuex store when leaving the site


I use vue.js with nuxt and want to remove something from the vuex store upon leaving the site.

I tried

beforeDestroy ({ store }) {
  store.commit('auth/setUserShowSecureAccountHint', false)
}

which didn't work as store is not known

and also

beforeDestroy () {
  this.store.commit('auth/setUserShowSecureAccountHint', false)
}

didn't work as store is not known.

How can I access the vuex store upon leaving the site?


Solution

  • You should prefix the store keyword by $ sign as follows :

    beforeDestroy () {
      this.$store.commit('auth/setUserShowSecureAccountHint', false)
    }