Vue components communication

前端 未结 6 1386
臣服心动
臣服心动 2020-12-01 09:18

I have two Vue components:

Vue.component(\'A\', {});

Vue.component(\'B\', {});

How can I access component A from component B? How does the

6条回答
  •  醉酒成梦
    2020-12-01 10:01

    It's best practice to use props and events.

    There are many examples online, like:

    • https://vuejs.org/v2/guide/components.html
    • https://alligator.io/vuejs/component-communication

    I recommend some reading on the topic.

    If the components are siblings and have no parent-child relationship it might be worth checking the architecture of your app.

    • Do A and B have a parent child relationship?
    • Is there a component C that is possibly the parent of A and B?

    If A and B are children of C, consider using props and events. Another way is to use props and sync, which can be helpful for form data:

    • https://medium.com/front-end-hacking/vues-v-model-directive-vs-sync-modifier-d1f83957c57c

提交回复
热议问题