Mehdi
Mehdi

Reputation: 488

Event is not a constructor in Creating Events on vue

I want to define and run events in vue

Befor i do such this :

window.Event = new Vue();

\\and in my component 
Event.$on('foo' , ()=>{
    //        do somthing 
    }
)
\\ and in some where else maybe in method of another component
Event.$emit('foo'); 

its work before but now when i define window.Event=new vue() i'm getting this error


partner.js:34649 Uncaught TypeError: Event is not a constructor

And this is list of modules that i imported before it:

import Vue from 'vue';
import Axios from 'Axios';
import swal from 'sweetalert2';
import Multiselect from 'vue-multiselect';
import 'vue-multiselect/dist/vue-multiselect.min.css';
import vue2Dropzone from 'vue2-dropzone'
import 'vue2-dropzone/dist/vue2Dropzone.min.css'
import 'froala-editor/css/froala_editor.pkgd.min.css';
require('froala-editor/js/languages/fa')
import VueFroala from 'vue-froala-wysiwyg'
Vue.use(VueFroala)
import VueFormWizard from 'vue-form-wizard'
import 'vue-form-wizard/dist/vue-form-wizard.min.css'
import { LMap, LTileLayer, LMarker, LTooltip } from 'vue2-leaflet';
import { Icon } from 'leaflet';
import 'leaflet/dist/leaflet.css';
delete Icon.Default.prototype._getIconUrl;
import PrettyInput from 'pretty-checkbox-vue/input';
import PrettyCheck from 'pretty-checkbox-vue/check';
import PrettyRadio from 'pretty-checkbox-vue/radio';
import Vuex from 'vuex';
window.Event = new Vue();

What do you suggest for create events like this? Or how to solve this error?

Upvotes: 1

Views: 1880

Answers (1)

tevemadar
tevemadar

Reputation: 13195

Before you tampered with it, Event() was a constructor. Apparently Vue and other parts of the code did not need it in the past, but it seems to be needed now.

Possible solution: name it something else, like

window.VueEvent = new Vue();

Upvotes: 4

Related Questions