main.js
import Vue from 'vue'App.vue
import App from './App.vue'
import Student from './Student.vue'
const EventBus = new Vue();
export default EventBus;
Vue.component("student",Student);
new Vue({
el: '#app',
render: h => h(App)
})
<template>Student.vue
<student></student>
</template>
<script>
import Vue from 'vue';
import EventBus from './main.js';
export default {
mounted () {
EventBus.$on('EVENT_NAME', function (payLoad) {
alert("worked!"+payLoad);
});
}
}
</script>
<template>
<button @click="emitMethod">Click</button>
</template>
<script>
import Vue from 'vue';
import EventBus from './main.js';
export default {
methods: {
emitMethod () {
EventBus.$emit('EVENT_NAME', 1233);
}
}
}
</script>
Result
No comments :
Post a Comment