0👍
You need to emit an event you want to listen to first, use vm.$emit() like this:
let vm = new Vue({
el:"#app",
methods:{
clickListener() {
this.$emit('eventName', 'sample-value');
}
}
})
vm.$on('eventName', function(value){
console.log(value); // 'sample-value'
});
EDIT: try something like this:
const vm = new Vue({
el: '#app',
mounted() {
const app = document.getElementById('app');
app.addEventListener('click', (event) => {
this.$emit('click', event);
});
}
});
vm.$on('click', (event) => {
console.log('click', event);
});
- [Vuejs]-How could I use materialize CSS CDN in nuxt.js?
- [Vuejs]-ES6 Vue and Webpack project doesn't run on IE11 but works on Chrome
Source:stackexchange.com