Official docs: https://vuex.vuejs.org/
Resources:
Official docs: https://vuex.vuejs.org/
Resources:
| import Vue from 'vue' | |
| import { store } from './store/store' | |
| new Vue({ | |
| el: '#app', | |
| store, | |
| components: { App }, | |
| template: '<App/>' | |
| }) |
| <template> | |
| <div id="app"> | |
| <div> | |
| <label for="flavor">Favorite ice cream flavor: {{ $store.getters.flavor }}</label> | |
| <input name="flavor" @input="changed"> | |
| </div> | |
| </div> | |
| </template> | |
| <script> | |
| import Form from './components/Form' | |
| import Display from './components/Display' | |
| export default { | |
| name: 'App', | |
| methods: { | |
| changed: function(event) { | |
| this.$store.commit('change', event.target.value) | |
| } | |
| } | |
| } | |
| </script> |
| import Vue from 'vue' | |
| import Vuex from 'vuex' | |
| Vue.use(Vuex) | |
| export const store = new Vuex.Store({ | |
| state: { | |
| flavor: '' | |
| }, | |
| mutations: { | |
| change(state, flavor) { | |
| state.flavor = flavor | |
| } | |
| }, | |
| getters: { | |
| flavor: state => state.flavor | |
| } | |
| }) |