Skip to content

Instantly share code, notes, and snippets.

@hootlex
Forked from nickbasile/Component.vue
Created December 8, 2016 00:47
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hootlex/e67344164b5ab8efbcb9591417a23c36 to your computer and use it in GitHub Desktop.
Save hootlex/e67344164b5ab8efbcb9591417a23c36 to your computer and use it in GitHub Desktop.
How to use a namespaced action in a Vue.js component
<template>
<div>
<button @click="increment">Increment</button>
</div>
</template>
<script>
import { mapActions } from 'vuex'
export default{
methods: {
...mapActions({
'increment': 'namespace/actionMethod'
})
}
}
</script>
@psy21d
Copy link

psy21d commented Jan 12, 2019

Great!

@nachodd
Copy link

nachodd commented May 28, 2019

Thanks!

@kofiasare
Copy link

kofiasare commented Sep 11, 2019

Many thanks

@anlek
Copy link

anlek commented Oct 3, 2019

Haha, Thank you for sharing!

@manavm1990
Copy link

If not changing name, can also do: // First argument for namespacing. methods: mapActions("namespace", ["actionMethod"])

@rizquadnan
Copy link

Thank you very sharing, very helpful!

@umang1802
Copy link

how to pass payload in such case?

@danielb1194
Copy link

danielb1194 commented Mar 27, 2021

how to pass payload in such case?

Like with any other method:
..mapActions({ increment: 'namespace/actionMethod' }) increment(payload)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment