【问题标题】:How to add type cheking for commit in vuex with TypeScript?如何使用 TypeScript 在 vuex 中添加类型检查以进行提交?
【发布时间】:2019-01-25 23:25:13
【问题描述】:

我的 vuex 存储中有这样的动作树

export const actions: SalaryActionTree<SalaryState, RootState> = {
    async setSalaryOperationUnpaidListByUserId(
       {commit}, {user_id, pageNum}) {
        try {
            let res = await SalaryOperationProvider.salaryOperationIndex({
                form: {
                    user_id,
                    payed: '0',
                },
                collectable: {pageNum},
            });
            commit({
                type: 'some-mutatation',
                data: res.data;
            });
        } catch (err) {

        }
    },
}

如何让 typescript 对提交参数进行类型检查?

【问题讨论】:

    标签: typescript vue.js vuex


    【解决方案1】:

    看起来 Vuex 本身并没有提供任何类型检查要提交的参数的方法:it accepts anything that has a type propertyweb search 找到了我 this thread,它提供了多种选择。

    【讨论】:

      【解决方案2】:

      这不是官方的解决方案,但你可以使用direct-vuex

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-20
        • 2020-01-03
        • 1970-01-01
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 2018-08-26
        • 2019-01-19
        相关资源
        最近更新 更多