-
-
Save hootlex/e67344164b5ab8efbcb9591417a23c36 to your computer and use it in GitHub Desktop.
How to use a namespaced action in a Vue.js component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<button @click="increment">Increment</button> | |
</div> | |
</template> | |
<script> | |
import { mapActions } from 'vuex' | |
export default{ | |
methods: { | |
...mapActions({ | |
'increment': 'namespace/actionMethod' | |
}) | |
} | |
} | |
</script> |
Thanks!
Many thanks
Haha, Thank you for sharing!
If not changing name, can also do: // First argument for namespacing. methods: mapActions("namespace", ["actionMethod"])
Thank you very sharing, very helpful!
how to pass payload in such case?
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
Great!