Last active
July 30, 2022 12:53
-
-
Save joesoeph/5b02942a5846855cf33f2c717c519839 to your computer and use it in GitHub Desktop.
Example using vuex using map helper
This file contains 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
// in this case Folder structure using nuxt. | |
// store/example.js | |
export const state = () => ({ | |
dataInput: "Hello guys!" | |
}) | |
export const actions = { | |
setDataInput({ commit }, payload) { | |
commit('dataInput', payload.target.value) | |
} | |
} | |
export const mutations = { | |
dataInput(state, payload) { | |
state.dataInput = payload | |
} | |
} | |
// ExampleVuex.vue component | |
<template> | |
<div> | |
<input type="text" placeholder="Input..." @input="setDataInput" :value="dataInput" /> | |
<p>{{ dataInput }}</p> | |
</div> | |
</template> | |
<script> | |
import { mapState, mapActions } from "vuex"; | |
export default { | |
computed: { | |
...mapState("example", ["dataInput"]), | |
}, | |
methods: { | |
...mapActions("example", ["setDataInput"]), | |
}, | |
}; | |
</script> | |
// parent component | |
<ExampleVuex /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment