In vue cli, how do you listen to a variable and then operate accordingly?

for example, I am responsible for logging in and obtaining user information in the user.vue component. In the getInfo.vue component, the user logs in and requests the corresponding info interface to obtain the relevant information.

so how can I trigger an ajax request in getInfo.vue after logging in in user.vue? Thank you

Mar.13,2021

vuex find out, if you have to, try broadcasting.


according to your description, the two components should be sibling components. So this is a problem of communication between sibling components. There are three solutions. Through the parent component, eventbus,vuex feels feasible


vuex can, http://www.bubuko.com/infodet.


  1. props feasible, user component definition variable passed to getInfo component, and watch passed variable
  2. in getInfo component
  3. eventBus is feasible. If the variable defined by user changes, emit customize the event, and perform on listening
  4. within the getInfo component.
  5. vuex is feasible. Variables are defined in store , user change variables, and getInfo components mapGetters get real-time listening

all of the above three are available, and components communicate

Menu