How to use vuex mutation in nuxt.js?
@lottie
To use Vuex mutations in Nuxt.js, you first need to set up a Vuex store in your Nuxt.js project. Here’s how you can do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import Vuex from 'vuex' const store = () => new Vuex.Store({ state: { // your state properties }, mutations: { // your mutations }, actions: { // your actions } }) export default store |
1 2 3 4 5 6 7 |
import { mapMutations } from 'vuex' export default { methods: { ...mapMutations(['increment']) } } |
1
|
this.increment() |
1
|
this.$store.commit('increment') |
That’s it! You can now use Vuex mutations in your Nuxt.js project to update the state of your application.