Vue && Vuex
by mckabue
HTML
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vuex"></script>
<div id="app">
<followers></followers>
</div>
JavaScript
Vue.component('followers', {
template: '<div>{{$store.state.arr}}</div>',
computed: {
newItem: function () {
return '123'
}
},
created () {
this.$store.commit('addArr', this.newItem);
}
});
const store = new Vuex.Store({
state: {
arr: []
},
mutations: {
addArr(state, newItem) {
state.arr.push(newItem);
}
}
})
const app = new Vue({
store,
el: '#app'
})