Vue
HTML
<div id="wrap">
<test-listen>
</test-listen>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
Vue.component('test-emit',{
data: function(){
return {};
},
methods: {
clickHandler : function(){
this.$emit('custom');
}
},
template : `
<div class='test_emit' v-on:click="clickHandler">
test
</div>
`
});
Vue.component('test-listen', {
data: function(){
return {};
},
methods: {
customHandler : function(){
console.log("works");
}
},
template: `
<div class='test_listen'>
<test-emit v-on:custom="customHandler"></test-emit>
</div>
`
});
new Vue({
el:"#wrap",
});