[Vuejs]-How to edit my store so it can take all of my inputs in array to my state?

0👍

What you are doing is basically overwriting your message for each iteration of your loop.

If you want to pass all the lines of your local data to your store, then in store.js message should be an array like so:

const state = {
  messages: []
  // ...
}

Change your action to:

setMessages: ({ commit, state }, inputs) => {
  commit('SET_MESSAGES', inputs.map(x => x.message));
  return state.message;
},

And in your component:

onSubmit() {
  this.setMessages(this.inputs);
}

Leave a comment