I am experimenting with VueJS to understand how to use emit and listen methods. I encountered some unexpected results that I cannot figure out. My expectation was for the initMap() function to be called and for the console to log the expected output, which it does, but an error message appears at the top of the page.
Uncaught TypeError: Cannot read property 'apply' of undefined
at Vue$3.Vue.$emit (vue.js:2186)
at Vue$3.emit (main.js:131)
at Vue$3.boundFn [as emit] (vue.js:167)
...
SENDING
import GISView from './components/GISView.vue';
import VueEvents from 'vue-events';
window.Vue = Vue;
Vue.use(VueEvents)
var App = window.App = new Vue({
el: '#app',
components: {
gisview: GISView
},
methods: {
initMap: function() {
this.$events.fire("MapLoaded");
}
}
});
LISTENING
<template>
<div ref="map" id="map" class="google-map" style="position: relative; overflow: hidden;">
<div style="height: 100%; width: 100%; position: absolute; top: 0px; left: 0px;">
</div>
</div>
</template>
<script>
import GoogleMaps from '../mixins/GoogleMaps.js';
export default {
mixins: [GoogleMaps],
data() {
return {
map: ''
}
},
mounted() {
this.$events.$on("MapLoaded", this.initMap());
},
methods: {
initMap: function() {
console.log("OK");
}
}
}
</script>