Function mapActions

  • Allows directly using actions from your store without using the composition API (setup()) by generating an object to be spread in the methods field of a component. The values of the object are the actions while the keys are the names of the resulting methods.

    Type Parameters

    Parameters

    Returns _MapActionsObjectReturn<A, KeyMapper>

    Example

    export default {
    methods: {
    // other methods properties
    // useCounterStore has two actions named `increment` and `setCount`
    ...mapActions(useCounterStore, { moar: 'increment', setIt: 'setCount' })
    },

    created() {
    this.moar()
    this.setIt(2)
    }
    }
  • Allows directly using actions from your store without using the composition API (setup()) by generating an object to be spread in the methods field of a component.

    Type Parameters

    Parameters

    Returns _MapActionsReturn<A>

    Example

    export default {
    methods: {
    // other methods properties
    ...mapActions(useCounterStore, ['increment', 'setCount'])
    },

    created() {
    this.increment()
    this.setCount(2) // pass arguments as usual
    }
    }

Generated using TypeDoc