[Vuejs]-Vue router and vuex issue with redirecting based on a value

0👍

Looks like you have a lot of duplicate and confusing code.

Why is there 2 of isPaid and isTrial in the state?

You also did not use the name property you provided to commit function.

The commit

commit('storeUser', {
    name: res.data.user.name,
    isPaid: res.data.user.company.stripe.isPaid,
    isTrial: res.data.user.company.stripe.isTrial
});
const store = new Vuex.Store({
    state: {
        userName: '',
        isPaid: false,
        isTrial: false,
    },
    mutations: {
        storeUser(state, data) {
            state.userName = data.name;
            state.isPaid = data.isPaid;
            state.isTrial = data.isTrial;
        },
    },
});

Now you access the state store.state.isPaid and store.state.isTrial.

You can see a working example at this jsfiddle. If you open up the console you can see how the current state is logged.

Leave a comment