Skip to content

Instantly share code, notes, and snippets.

@joesoeph
Last active July 30, 2022 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joesoeph/5b02942a5846855cf33f2c717c519839 to your computer and use it in GitHub Desktop.
Save joesoeph/5b02942a5846855cf33f2c717c519839 to your computer and use it in GitHub Desktop.
Example using vuex using map helper
// 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