0
votes

I have a button inside my vue component

<button class="search-participant__btn" @click="getParticipant({iin, index, switchIsLoading})">Найти</button>

getParticipant, is a function inside actions vuex, that i imported to this component

export const getParticipant = ({commit, getters}, {iin, index, callback}) => {
    callback(true);
    axios.post('/getParticipant', {iin}).then(response => {
        if(response.data.success) {
        }
    })
}

but when i wanted to call function that i pass into getParticipant, it doesn't work, i just need to change local state data named isLoading to true, when i click the button. And then switch it into false, when response is come back

How to make it correctly?

1
Have you read this: vuex.vuejs.org/guide/actions.html? - Psidom
yes, but it's not solved my problem. My function that changes local state is outside of actions.js. So thats why i passed my function into vuex action function as a parameter - Hanzo Hattori

1 Answers

0
votes

In your vuex create a state called isLoading and also a mutation that updates the isLoading state. Once these are created inside your action you can use commit (isLoading, true) and after its finished isLoading(false).

You can then access isLoading in your component using a computed function, see the docs.