Home  >  Q&A  >  body text

javascript - How does vue axios control the execution order in different components?

For example, my case is to request public data in a public component. The request in the subcomponent depends on the public data. If the public data has not yet requested the data, the subcomponent will report an error when it starts to request, because the request in the subcomponent The parameter is the result of the request in the public component, and vuex is used to pass the data. How can the public data request be completed before the sub-component starts requesting? ? ?

phpcn_u1582phpcn_u15822663 days ago1075

reply all(3)I'll reply

  • 習慣沉默

    習慣沉默2017-07-05 11:10:21

    You can use vue’s watch and wathc to make sub-component ajax requests only when the data in vuex exists

    reply
    0
  • 黄舟

    黄舟2017-07-05 11:10:21

    You can introduce a message subscription model
    https://github.com/holdnoWby/...
    The same is used in VUE
    Refer to /q/10... this answer

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-07-05 11:10:21

    Thank you for your answers, but I solved it very simply with my own method. To execute this.$store.dispatch('setHomeData') request on the APP.vue page, just add v-if=" on the router-view tag. homeData" will do. As long as there is data, the subcomponent page will appear and the request inside will be executed.

    reply
    0
  • Cancelreply