[Vuejs]-Vuex assign null conditionally in action

1👍

You could use the conditional operator:

updateTicketCustomer ({commit, state}, selectedCustomer) {
    axios.patch('/tickets/' + state.currentTicket.id, {
      customer_id: selectedCustomer !== null ? selectedCustomer.id : null
    })
    .then((response) => {
            commit('UPDATE_TICKET_CUSTOMER', selectedCustomer)
    });  
}

The syntax is, basically:

<condition> ? <returned if true> : <returned if false>

Leave a comment