<div id="app">
<textarea
v-model="title"
@keydown.enter.prevent
@keyup.enter="addItem"
></textarea>
<ul>
<li v-for="n in $store.state.items">{{ n.title }}</li>
</ul>
</div>
const store = new Vuex.Store({
state: {
items: Array.from('abcd', n => ({ title: n.repeat(3) })),
},
mutations: {
addItem: (state, item) => state.items.push(item),
},
});
new Vue({
el: '#app',
store,
data: () => ({
title: '',
}),
methods: {
addItem() {
const title = this.title.trim();
if (title) {
this.$store.commit('addItem', { title });
this.title = '';
}
},
},
});