Vue Event.fire Event.listen
window.Event = new class {
constructor() {
this.vue = new Vue();
}
fire(event, data = null) {
this.vue.$emit(event, data);
}
listen(event, callback) {
this.vue.$on(event, callback);
}
}
Vue.component('services', require('./components/gru/Services.vue'));
const app = new Vue({
el: '#app',
created() {
Event.listen('applied', () =>
console.log('Event applied handling it!')
)
}
});<template>
<input type="text" @blur="onTextApplied">
</template>
<script>
export default {
mounted() {
console.log('Componente Services loaded!')
},
data() {
return {}
},
methods: {
onTextApplied() {
console.log('Event applied Fired!')
Event.fire('applied')
}
}
}
</script>