【问题标题】:TypeError: Cannot read property 'commit' of undefinedTypeError:无法读取未定义的属性“提交”
【发布时间】:2021-07-31 14:58:32
【问题描述】:

请帮我解决这个问题,我正在使用 vue js v2 并且我也是新手,但是我遇到了一些无法读取提交的问题。当我通过保护路由登录并重定向到我的仪表板时

谁能帮帮我?

store.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state:{
        authenticated: false
    },
    mutations: {
        setAuthentication(state, status){
            state.authenticated = status
        }
    },
})

export default store

方法

methods: {
       login(){
           axios.post('/api/v1/login', this.form)
           .then(response =>{
            //    this.$router.push('dashboard')
                  this.$store.commit('setAuthentication', true);
                  this.$router.replace({name: 'dashboard'})
           })

       }
   }

【问题讨论】:

    标签: laravel vue.js vuex vue-router


    【解决方案1】:

    试试

    $store.commit('{fileName}/{mutatorName}', value);
    

    你的情况

    $store.commit('store/setAuthentication', true);
    

    【讨论】:

    • 但是仍然无法正常工作@Нигилист Джордан
    【解决方案2】:

    试试这个。

        import Vue from 'vue'
        import Vuex from 'vuex'
        Vue.use(Vuex)
        
        export default new Vuex.Store({
            state : { 
                authenticated: false, 
            }, 
            mutations: {
                setAuthentication(state, data) {
                    state.authenticated= data;
                  },
            }, 
        })
    
    
    this.$store.commit('setAuthentication',true);
    

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2020-12-24
      相关资源
      最近更新 更多