小编Naz*_*iuk的帖子

如何从另一个动作调用 Pinia 动作?

有没有办法从同一商店中的另一个操作调用 Pinia 商店操作?例如,我有这样的 Pinia 商店:

export const useCounter = defineStore({
    id: 'counter',

    state: () => ({
        counter: 0
    }),

    actions: {
        addOne() {
            this.state.counter++
        },
        addTwo() {
            // Can i call here addOne action?
            // Things like this not working:
            this.addOne();
            this.addOne();
            // This is not working too:
            this.actions.addOne();
            this.actions.addOne();
        }
    }
});

Run Code Online (Sandbox Code Playgroud)

我可以在 addTwo 中调用 AddOne 操作吗?

vue.js pinia

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

pinia ×1

vue.js ×1