为什么状态不更新为新的突变(在我的情况下是新帖子)?

时间:2019-09-14 12:55:00

标签: vuejs2 vuex

我的吸气剂工作正常,并显示硬编码状态数据。但是当我使用动作和变异添加新帖子时,不会显示新帖子。

我正在使用最新版本的Vue和Vuex。我要更新的数据是从用户创建的组件中获取的,应该显示在列表组件中。

/modules/lists_data

const actions = {
 createNew ({commit}, payload) {
    const newItem = {
        title: payload.title,
        location: payload.location,
        imageUrl: payload.imageUrl,
        description: payload.description,
        date: payload.date,
        id: 'skwnkqnclqinq'
    };
    commit('addNew',newItem);
}
};

const mutations = {
addNew: (state,payload) => state.loadedLists.push(payload)

};

/components/create
this is the script

import { mapActions } from 'vuex' 

export default {
data() {
    return {
        title: '',
        location: '',
        imageUrl: '',
        description: '',
        inputRules: [
            v => v.length >=3 || 'Minimum length is 3 characters'
        ]
    }
},
methods: {
  ...mapActions(['createNew']),
    onCreateNew(){
        if(this.$refs.form.validate()){
            const newItem = {
                title: this.title,
                location: this.location,
                imageUrl: this.imageUrl,
                description: this.description,
                date: new Date(), 
            }
            this.$store.dispatch('createNew',newItem)


        }
    }

}
}

0 个答案:

没有答案