by icemelt8 · 10y ago · 0 comments
I don't really like Vue.js after coming from ReactJS, main reason is how hard is it to create components, which is the main attraction of React.
This is ReactJS code for a List group that has list items which are composed of buttons, can anyone post the Vue.JS equivalent code?
var Button = function(props){
return <button>{props.text}</button>
}
var ListItem = function(props){
return <div>I am a item <Button text="click me" /></div>
}
var ListGroup = React.createClass({
render: function() {
return <div>
<ListItem name="hello"/>
</div>;
}
});ReactDOM.render(
<ListGroup />,
document.getElementById('container')
);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/.*Updated with simpler code and JSfiddle example
:-) just sayin;-)