Last active
December 17, 2017 14:53
-
-
Save nasum/dad96410d753d9a31e4f to your computer and use it in GitHub Desktop.
Vue.js用のFluxライクなライブラリVuexを試してみる ref: https://qiita.com/nasum/items/b2f11a392bf8fb125610
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
export default { | |
addTodo: 'ADD_TODO' | |
} |
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
:actions.js | |
export default { | |
addTodo: 'ADD_TODO' | |
} |
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
import Vue from 'Vue'; | |
import TextForm from './components/TextForm.vue'; | |
import ToDoList from './components/ToDoList.vue'; | |
import store from './store/'; | |
window.onload = function(){ | |
var main = new Vue({ | |
el: "body", | |
data: store.state, | |
components: { | |
"text-form": TextForm, | |
"to-do-list": ToDoList | |
} | |
}) | |
} | |
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
export default { | |
ADD_TODO (state, text) { | |
state.todos.push(text) | |
} | |
} |
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
<template> | |
<div> | |
<input type="text" v-model="input" @keyup.enter="addTodo"/> | |
</div> | |
</template> | |
<script> | |
import store from '../store/'; | |
export default { | |
props: ['input'], | |
methods: { | |
addTodo: function(e){ | |
var text = e.target.value; | |
store.actions.addTodo(text); | |
e.target.value = ''; | |
} | |
} | |
} | |
</script> |
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
<template> | |
<ul> | |
<li v-for="todo in todos">{{todo}}</li> | |
</ul> | |
</template> | |
<script> | |
export default { | |
props: ['todos'] | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment