如何在不使用组件标签的情况下将数据从一个 vue 组件传递到另一个 vue 组件

How to pass data from one vue component to another vue component without using the component tag

我想将数据从我的 vue 文件传递​​到布局部分中存在的另一个组件。我知道我可以使用 props 但是为了使用 props 我需要在 vue 文件中初始化我想从中传递数据的组件。但是我不想在我的 Vue 上初始化组件我只想传递数据。

这是下面的结构。 在我的 default.vue 中,我有这两个组件。

  <right-side-bar-org  v-if="$route.name=='organisation'"></right-side-bar-org>
  <right-side-bar-search  v-if="$route.name=='search'"></right-side-bar-search>

我已经用 props 声明了组件。 但是为了传递道具,我必须从我的 default.vue 传递它。 但是我有另一个组件search.vue,我想从中将数据传递给这些组件而不在搜索vue中声明该组件。 有什么办法可以做到这一点。

这些问题的发生是因为you're not using a store。在全局范围内将数据放在 vue 之外的新位置。然后 vue 的东西可以在创建时绑定到它,在销毁时解开,不同的 vms 甚至不需要知道彼此。