在商店vue js中改变状态

时间:2017-04-22 22:25:37

标签: javascript vue.js vuejs2

我在通过ajax设置变量时遇到问题。



const store = new Vuex.Store({
    state: {
        conversationsList: []
    },
    mutations: {
        conversationList(state, payload) {
          state.conversationList = payload;
        }
    }
});

setInterval(function () {
    axios.get('/conversation/get-conversations')
        .then((response) => {
            store.commit('conversationList', response.data);
        });
}, 1000);




我无法理解为什么state.conversationList = payload不会改变值?

甚至用简单的数组赋值替换ajax调用,例如

        var testList = [
            {id: 1, author:  'john', type: 'follower', lastMessage : 'hi'}
        ];

        store.commit('conversationList', testList);

不起作用

0 个答案:

没有答案
相关问题