vuejs radio button component

后端 未结 2 1717
慢半拍i
慢半拍i 2020-12-13 11:13

I trying to make this custom radio button component to work in vuejs. How do I make the radio button checked with a value from parent component. I know you use v-model and s

2条回答
  •  Happy的楠姐
    2020-12-13 11:54

    I'd personally do it another way, to keep a v-model directive and avoid an @change event (which could be replaced by @input if any other logic has to be performed). The thing here is that I the v-model value is equal to the "value" props in the radio-button component.

    props: {
        value: {},
        v_value: {},
        ....
    }
    

    So all you have to do is pass the real current value to make some checks and $emit the value on click on a label, or on change on the input if you don't have any label.

    
    

    I also added (but commented it) a version with simple html markup in case you want custom-looking radio buttons :

    {{ label }}

    https://jsfiddle.net/Zyfraglover/ndcp8t6e/

提交回复
热议问题