- 博客(5)
- 收藏
- 关注
原创 完整代码完整代码
type GetMutations = Module extends { mutations: infer M } ? M : nevertype AddPrefix<Prefix, Keys> = ${Prefix & string}/${Keys & string}type GetSubModuleKeys<Module, Key> = Module extends { modules: infer SubModules }? AddPrefix<Ke
2020-09-16 16:38:58 939
原创 以这个 cart 模块为例,分解一下每个工具类型得到的结果:
cart: {mutations: {add() { },remove() { }}modules: {subCart: {mutations: {add() { },}}}},type GetModuleMutationKeys<Module, Key> =// ‘cart/add’ | ‘cart | remove’AddPrefix<Key, keyof GetMutations> |// ‘cart/subCart/add’GetSubMod
2020-09-16 16:38:14 122
原创 cart 模块下还可能有别的 Modules,比如这样:
cart: {mutations: {add() { },remove() { }}modules: {subCart: {mutations: {add() { },}}}},cart: {mutations: {add() { },remove() { }}modules: {subCart: {mutations: {add() { },}}}},cart: {mutations: {add() { },remove() { }}modul
2020-09-16 16:37:38 92
原创 重头戏在于,我们需要根据 Modules 这个泛型,也就是对应结构:
modules: {cart: {mutations: {add() { },remove() { }}},user: {mutations: {login() { }},modules: {admin: {mutations: {login() { }},}}}}modules: {cart: {mutations: {add() { },remove() { }}},user: {mutations: {login() { }},module
2020-09-16 16:37:03 62
原创 本文就利用这个特性,简单实现下 Vuex 在 modules 嵌套情况下的 dispatch 字符串类型推断,先看下效果,我们有这样结构的 store:
const store = Vuex({mutations: {root() {},},modules: {cart: {mutations: {add() {},remove() {},},},user: {mutations: {login() {},},modules: {admin: {mutations: {login() {},},},},},},})const store = Vuex({mutations: {root() {},},
2020-09-16 16:36:26 576
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人