I am struggling to figure out how to pass a value that is set inside a button to a child component. Essentially, I want the value of the clicked button that displays a percentage to be passed as a prop value. This prop value should update depending on which button I click. Do I need to utilize a v-model
? If so, how can I achieve this? Below is my current progress...
ButtonGroup.vue
<button class="button" v-on:click="percentageValue(0.05)">5%</button>
<button class="button" v-on:click="percentageValue(.10)">10%</button>
<button class="button" v-on:click="percentageValue(.15)">15%</button>
<button class="button" v-on:click="percentageValue(.25)">25%</button>
<button class="button" v-on:click="percentageValue(.50)">50%</button>
<script>
export default {
name: 'ButtonGroup',
data(){
return{
percentage: null
}
},
methods:{
percentageValue(value){
this.percentage = value;
}
},
props:['percentage']
}
</script>
Calculator.vue
<ButtonGroup :percentage="percentage"/>