A
A
Alexander Florenko2018-12-06 19:10:00
Vue.js
Alexander Florenko, 2018-12-06 19:10:00

How to pass values ​​from a state to a child component?

Hello.
I have a component with 2 inputs.

...
<input class="reg__label__input" type="email" disabled 
       :placeholder="$t('registrations.emailPlaceholder')" 
       v-model="$store.state.registrations.user_email">
...
<input class="reg__label__input" :type="passwdType" ref="passwdInput" 
       v-model="$store.state.registrations.password" 
       @input="eventPassInput($event)" 
       @blur="checkPlaceholder()">
...

This component will be used in several places.
And v-modelit will always be different
And always from state
Here I can’t figure out how to properly pass data from the parent component so that I can change it from the child.
Tried in many ways, and propsand computed
But something is clearly wrong.
I ask for your help/advice.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-12-06
@SkipTyler

I tried in many ways <...> something is clearly wrong

And how did they try, why didn't they show it? Do you think that here all telepaths, clairvoyants - will determine your "something" for one or two in the absence of details? No, it won't.
And for
it's not enough for you to cut off your hands. Think documentation is not for you? - Well, you are wrong. And strongly. You should not change the state outside of mutations, make a computed property:
user_email: {
  get() {
    return this.$store.state.registrations.user_email;
  },
  set(val) {
    this.$store.commit('update_user_email', val);
  },
},

The name of the property being edited can be formatted as a parameter of the component, and passed to the mutation along with the new value (or generally pass an object whose properties will be mixed with the object in the state using Object.assign).

G
grinat, 2018-12-09
@grinat

All components always have access to the entire state, there is no need to transfer it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question