我遇到了Vue.js应用程序(版本2.4)的问题。 我创建了一个event.js文件来定义我的eventBus,如下所示:
import Vue from "vue";
const EventBus = new Vue();
export default EventBus;
在其他组件中,我导入该文件并使用EventBus来捕获/发出各种事件。问题是当我尝试将其作为另一个组件的属性传递时:
<canvas-overlay
:eventBus="eventBus"
:fn="getBuildings">
</canvas-overlay>
</template>
<script>
import CanvasOverlay from "components/src/core/Map/CanvasOverlaySingleEl.vue";
import eventBus from "../../event";
console.log(eventBus);
export default {
...
}
console.log的输出是合法的:
Vue$3 {_uid: 0, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: Vue$3, …}$attrs: (...)$children: []$createElement: ƒ (a, b, c, d)$listeners: (...)$options: {components: {…}, directives: {…}, filters: {…}, _base: ƒ}$parent: undefined$refs: {}$root: Vue$3 {_uid: 0, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: Vue$3, …}$scopedSlots: {}$slots: {}$vnode: undefined_c: ƒ (a, b, c, d)_data: {__ob__: Observer}_directInactive: false_events: {close-modal: Array(1), event: Array(1), map-moved: Array(1), address-search: Array(1), delete-credit-card: Array(1), …}_hasHookEvent: false_inactive: null_isBeingDestroyed: false_isDestroyed: false_isMounted: false_isVue: true_renderProxy: Proxy {_uid: 0, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: Vue$3, …}_self: Vue$3 {_uid: 0, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: Vue$3, …}_staticTrees: null_uid: 0_vnode: null_watcher: null_watchers: []$data: (...)$http: (...)$isServer: (...)$promise: (...)$props: (...)$resource: (...)$ssrContext: (...)$url: (...)get $attrs: ƒ reactiveGetter()set $attrs: ƒ reactiveSetter(newVal)get $listeners: ƒ reactiveGetter()set $listeners: ƒ reactiveSetter(newVal)__proto__: Object
所以我在组件中有busEvent。问题是在子组件(在本例中为canvas-overlay)中,eventBus未定义。
这是道具的定义:
eventBus: {
type: Object,
required: true,
},
我错过了什么?