4 ms·
I'm not versed in React but I think this achieves the same thing - 1. Create your custom component: var btnComp = { props: ['text'], template: '<div
by welanes 10y ago
I'm not versed in React but I think this achieves the same thing -
1. Create your custom component:
var btnComp = {
props: ['text'],
template: '<div>I am a button <button v-html="text"></button></div>'
}
2. Register it:
new Vue({
el: 'body',
components: {
'custombtn': btnComp
}
})
3. Display it:
<custombtn :text="'hello'"></custombtn>
That's anything but hard. Here: https://jsfiddle.net/v5s77r2x/ https://jsfiddle.net/v5s77r2x/.
*Updated with simpler code and JSfiddle example
- woogley 10y agoIt can even be closer to React than that, especially with JSX render functions. You don't even need the view to name itself: export default Vue.extend({ props: ['text'], render() { return <div>I am a button <button>{this.text}</button></div>; } });
- welanes 10y agoUseful to know. Cheers.