【问题标题】:How can I access the vuex store when leaving the site离开站点时如何访问vuex商店
【发布时间】:2020-04-06 21:45:48
【问题描述】:

我将 vue.js 与 nuxt 一起使用,并希望在离开站点时从 vuex 存储中删除一些内容。

我试过了

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

不知道哪个商店不工作

还有

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

没有工作,因为store 未知。

离开站点后如何访问 vuex 商店?

【问题讨论】:

  • 你为什么要这样做?存储不持久。所以当他们离开商店时也消失了
  • “离开”是指他们点击了指向另一个页面的 nuxt 链接。所以这不涉及页面重新加载,因此商店中的所有内容仍然存在

标签: vue.js vuex nuxt.js


【解决方案1】:

您应该在store 关键字前加上$ 符号,如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-24
    • 2020-12-07
    • 2020-02-05
    • 2017-12-05
    • 2021-10-20
    • 2018-09-13
    • 2018-05-19
    • 2018-12-19
    相关资源
    最近更新 更多