从 3.x 迁移到 4.0
用户现在应该使用新引入的 createStore 方法来创建 store 实例。
// 旧
// new Store(...)
// 新
export const store = createStore({
state() {
return { count: 1 };
},
});
TypeScript 支持
-
为了修复 issue #994,Vuex 4 删除了 this.$store 在 Vue 组件中的全局类型声明。
-
当使用 TypeScript 时,必须声明自己的模块补充(module augmentation)。
“createLogger”函数从核心模块导出
// 旧
// createLogger 方法从 vuex/dist/logger 文件中导出
// 新
import { createLogger } from "vuex";
全新的“useStore”组合式函数
import { useStore } from "vuex";
export default {
setup() {
const store = useStore();
},
};