A
A
Alex2019-09-16 13:14:19
Vue.js
Alex, 2019-09-16 13:14:19

Catch store vue update event?

In general, the project is written in vue, vuex is connected. There is a page/component index.vue in the hook create, a request to the server to receive data is located. The data that is received is written to the store. Further along the hierarchy is the child page / component home.vue in computed, I get data through mapStatewhat is stored in my store. On the same page there are several input fields, so they should contain data that came upon request, which can then be rewritten and updated again.
So, the data() {}variables / models for these fields are stored in, how can I update them so that the input fields contain the data that came in? it's just that in the create of this child component, I can't do it. the request is asynchronous
I hope I explained it clearly
Addition
There are inputs

<xar-text-field 
  v-model="newPosTerminal.locationId" 
  :name="'pos-terminal-location'" 
  :label="'Location'"
  :full-width="true"/>
<xar-text-field 
  v-model="newPosTerminal.signatureKey" 
  :name="'pos-terminal-signature-key'" 
  :label="'Signature key (Webhooks)'"
  :full-width="true"/>

and here is the js part
export default {
  data() {
    return {
      newPosTerminal: {
        type: 0,
        accessToken: null,
        locationId: null,
        signatureKey: null,
        webhook: null,
      },
    }
  },
  computed: {
    place() {
      return this.$store.getters.getPlaces.filter(elem => elem.id === +this.$attrs.id)[0];
    },
  },
  created() {
    this.SET_LOADED(false);
    this.newPosTerminal = {
      type: 0,
      accessToken: this.place ? this.place.accessToken : null,
      locationId: this.place ? this.place.locationId : null,
      signatureKey: this.place ? this.place.signatureKey : null,
      webhook: this.place && this.place.webhook ? this.place.webhook : null,
    };
  },
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question