Vue() 构造函数中的 vuex "store" vs "data: store",哪个最好?

vuex "store" vs "data: store" in Vue() constructor, which is best?

Vue 文档提到在构造函数上使用 "data" 选项,以保留 global/shared 数据: https://vuejs.org/v2/guide/state-management.html

这是有道理的。

Vuex 文档传递 "store" 对象,但没有 属性 名称: https://github.com/vuejs/vuex/blob/dev/examples/counter/app.js

new Vue({
  el: '#app',
  store,
  render: h => h(Counter)
})

不应该是

new Vue({
  el: '#app',
  data: store,
  render: h => h(Counter)
})

?

其他示例将其传递为 "store: store" https://ypereirareis.github.io/blog/2017/04/25/vuejs-two-way-data-binding-state-management-vuex-strict-mode/

但 "store" 没有记录在案 属性: https://vuejs.org/v2/api/

在您的 Vue 实例上使用 store 对于

只是 shorthand

store: store

https://ariya.io/2013/02/es6-and-object-literal-property-value-shorthand

在您的主实例上设置 store 是 Vuex 的一部分,也是 Vuex 如何与您的商店交互的一部分,因此需要它。

如果您要在没有 Vuex 的情况下使用自己的全局状态设置,那么将您自己的商店添加到数据中就完全没问题了。事实上,当还不需要像 Vuex 这样的完整设置时,很多应用程序都会这样做。