Skip to content

Instantly share code, notes, and snippets.

@LORD-KAY
Last active August 19, 2020 10:10
Show Gist options
  • Save LORD-KAY/9b91dbc19af24303264cc7e2a1398984 to your computer and use it in GitHub Desktop.
Save LORD-KAY/9b91dbc19af24303264cc7e2a1398984 to your computer and use it in GitHub Desktop.
Vue JS Component implementing a simple dispatch action for vuex store
<template>
<div>
<input type="text" v-model="todo" name="todo" id="addtodo"/>
<button @click="addTodo">Add New Todo</button>
</div>
</template>
<script>
export default {
name: "Todo",
data() {
return {
todo: "Buy milk at the grocery store" // default value for the input field
}
},
methods: {
addTodo() {
this.$store.dispatch("addTodoItem", this.todo)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment