In my vue/cli 4/vuex / bootstrap-vue project app I have big page of ads listings with modal dialogs defined and I want to move dialogs to separate *.vue file, as these dialogs would be used in other pages too To communicate when dialog must be opened I emit events, and these events are not triggered in my separate *.vue file. In src/views/ads/AdsListing.vue I define:
<template>
<b-card class="frontend_listing_container">
...
<ads-modal></ads-modal>
</b-card>
</template>
<script>
import Vue from 'vue'
import VueResource from 'vue-resource'
Vue.use(VueResource)
import {bus} from '@/main'
import appMixin from '@/appMixin';
...
Vue.component('ads-modal', require('../ads/AdsModal.vue').default);
export default {
data() {
...
methods: {
runEditAdModal(ed_id) {
console.log('runEditAdModal ed_id::')
console.log(ed_id) // IN THE CONSOLE I SEE THIS method is called
console.log('+++ runEditAdModalbus::')
console.log(bus) // AND VALID BUS OBJECT
bus.$emit('showEditAdModal', ed_id)
}
In src/views/ads/AdsModal.vue I try to catch event in component events :
<script>
import Vue from 'vue'
import VueResource from 'vue-resource'
...
import {bus} from '@/main'
import appMixin from '@/appMixin';
...
export default {
data() {
return {
...
}
},
name: 'adsModal',
created() {
alert( 'src/views/ads/AdsModal.vue CREATED::' ) // I DO NOT SEE THIS ALERT POPUP
}, // created() {
mounted() {
alert( 'src/views/ads/AdsModal.vue MOUNTED::' ) // I DO NOT SEE THIS ALERT POPUP
bus.$on('showEditAdModal', (ed_id) => {
console.log('showEditAdModalged ed_id::')
console.log(ed_id)
...
}) // bus.$on('page_changed', (from, to) => {
}, // mounted() {
As events are not triggered, showEditAdModal event is not cathced. What is wrong and how to fix it ?
"bootstrap-vue": "^2.1.0",
"font-awesome": "^4.7.0",
"moment": "^2.24.0",
"moment-timezone": "^0.5.27",
"vue": "^2.6.10",
"vue-date-pick": "^1.2.1",
UPDATED # 1: a) with
Vue.component('ads-modal', require('../ads/AdsModal.vue'));
I got warning :
vue.runtime.esm.js?2b0e:619 [Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <AdsModal>
<AdsListingPage>
<HomePage> at src/views/Home.vue
<AppContainer> at src/App.vue
<Root>
But created/mounted events are not triggered;
b) with line
Vue.component('ads-modal', () => import('../ads/AdsModal.vue'))
no warning and created/mounted events are not triggered anyway.
c) I tried to move import into src/main.js (commenting it in my src/views/ads/AdsListing.vue) and the same : created/mounted events are not triggered and I do not know how to trigger methods in AdsModal.vue.
src/views/ads/AdsModal.vue
and this h1 title I see on the page