为什么vue存储状态定义不同? (Nuxt,Vue)

问题描述 投票:1回答:1
// nuxt vuex module
export const state = () => ({
  test : '',
});

// state should be a method that returns an object in store/index.js 
export const state = {
  test : '',
};


// pure vue or classic mode
const store = new Vuex.Store({
  state: {
    count: 0
  },
})

为什么在模块模式下使用vuex时,为什么需要在nuxt中将状态返回给函数?

我不知道为什么。

在发生突变和动作的情况下,如果立即分配对象,分配状态也是正常的吗?

javascript vue.js vuex nuxt.js nuxt
1个回答
0
投票

很好的问题,我也不确定。我唯一能找到的是this comment。显然是要解决并发问题,这是Vue在浏览器中不会遇到的问题。

例如,关于为商店文件中的状态返回一个函数,实际上是Evan将其实现到Nuxt.js中以避免在两个并发请求之间具有相同的状态

© www.soinside.com 2019 - 2024. All rights reserved.