【发布时间】:2021-11-18 17:13:59
【问题描述】:
我对如何将按钮内定义的值传递给子组件感到有些困惑。基本上,显示百分比的单击按钮的值应该是道具值。这个道具值应该根据我点击的值而改变。我应该使用 v 模型吗?如果是这样,怎么做?这是我到目前为止所拥有的......
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){
return this.percentage = value;
}
},
props:['percentage']
}
</script>
计算器.vue
<ButtonGroup :percentage="percentage"/>
【问题讨论】:
标签: javascript vue.js vue-component vuejs3