Vue
by Roland Doda
HTML
<div id="app">
<parent-component></parent-component>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
.text {
background: blue;
padding: 8px 10px;
cursor: pointer;
}
Vue
Vue.component('child-component', {
data: function() {
return {
text: 'hi i am a text from child component'
}
},
render(h) {
return h('div', {
class: ['text'],
on: {
click: this.clicked
}
},
['Click me,please']
)
},
methods: {
clicked() {
this.$emit('click', this.text)
}
}
})
Vue.component('parent-component', {
render (h) {
return h('child-component', {
on: {
click: this.clicked
}
})
},
methods: {
clicked(data_passed_from_child) {
alert(`From child passed: ${data_passed_from_child}`)
}
}
})
new Vue({
el: "#app",
})