小编S. *_*ooq的帖子

分派动作后获取 vuex 存储状态

我正在Laravel 6 + Vue + Vuex创建一个聊天应用程序。我想调用 vuex store 并在调度操作完成后获取状态,然后我想在 vue 组件中对该状态进行一些处理。

ChatWindow组件中

mounted: function () {
    this.$store.dispatch('setContacts').then(() => {
        console.log('dispatch called')
        // I want to call the getter here and set one of the data property
    });
}
Run Code Online (Sandbox Code Playgroud)

动作.js

setContacts: (context) => {
    axios.post('/users').then(response => {
        let users = response.data;
        // consoled for testing
        console.log(users);
        context.commit('setContacts', users);
    });
}
Run Code Online (Sandbox Code Playgroud)

mutators.js

setContacts: (state, users) => {
    state.contacts = users;
},
Run Code Online (Sandbox Code Playgroud)

请参阅下面的屏幕截图。调度的 then 方法在action.js中的 …

laravel vue.js vuex

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

标签 统计

laravel ×1

vue.js ×1

vuex ×1