R
R
riksisharakshas2018-08-08 22:08:48
Vue.js
riksisharakshas, 2018-08-08 22:08:48

How to track multiple events on a component?

The crux of the matter is, there is a Root element, it has a component that generates many events and changes the state of the Root,

<user-form v-bind:formprops='userProps' @is-active="userProps.isActive = !userProps.isActive" @first-name-input="userProps.firstName = $event" @last-name-input="userProps.lastName = $event"></user-form>

Maybe I'm doing something wrong, but a lot of @some-event is annoying, a knowledgeable person briefly said that you can somehow, roughly speaking, send the entire mutable object up, but I didn’t find anything, share the article or your solutions.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2018-08-08
@riksisharakshas

you can somehow, roughly speaking, send the entire mutable object upstairs

Can.
Or a key-value pair. In this case, the handler in the parent component will remain alone, and will look something like this:
methods: {
  onChange(e) {
    this.userProps[e.name] = e.val;
  }
}

A
Alexander Aksentiev, 2018-08-08
@Sanasol

there is vuex for that.

E
Evgeniy S, 2018-08-08
@evgensenin

Where you emit events like first-name-input, add another change and really pass the entire object up at once. so many forms do

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question