Vuex - 如何在不同的选项卡上保持存储更新?

jet*_*lej 10 vue.js vuex

我有一个使用 Vuex 的 Vue 应用程序。如果我打开了两个选项卡,则一个选项卡中对商店的更改不会显示在另一个选项卡中。

如何确保所有选项卡上的存储/数据立即同步?

const store = new Vuex.Store({
  state: {
    tasks: []
  },
  getters: {
    tasks: state => state.tasks
  }
}
Run Code Online (Sandbox Code Playgroud)

在模板中:

computed: {
  tasks: function () {
    return this.$store.getters.tasks
  }
}
Run Code Online (Sandbox Code Playgroud)

Imr*_*e_G 9

默认情况下这不起作用。您可以使用 vuex-shared-mutations。见这里:https : //github.com/xanf/vuex-shared-mutations