vue.js - vuex 使用this.$store.commit()提示不是function

查看:1380
本文介绍了vue.js - vuex 使用this.$store.commit()提示不是function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

1、使用vuex 在组件里使用this.$store.commit()提示不是function

在enter.vue中

        created () {
            this.$store.commit('changeIndexConf', {
                isTab: true,
                isBack: false,
                title: ''
            });
        }

3.store.js

import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        //公共
        comm: {
            loading: false,
            login: {
                memberId: '',
                userData: ''
            },
            indexConf: {
                isTab: false, //是否显示tab页
                isBack: false, //是否显示返回
                title: '' //标题
            }
        }
    },
    mutations: {
        /*
         * 修改header的信息
         *比如是否有回退按钮,标题显示内容
         * */
        changeIndexConf: (state, data) => {

            Object.assign(state.comm.indexConf, data);
        }
    },
    actions: {     
    },
    getter: {
    }
});
export default store

4、提示

enterpiseList.vue?c518:15 Uncaught TypeError: this.$store.commit is not a function

解决方案

我刚也遇到了这个问题,打开你的package.json,看看vuex是不是装成了1.0版本

这篇关于vue.js - vuex 使用this.$store.commit()提示不是function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆