应纳税所得额=收入-费用-免税收入-本期其他扣除小计 怎么拿到form-item输入的值income cost subtotal taxExemptIncome传递给acTaxableAmount
您可以使用以下方法将form-item输入的值传递给acTaxableAmount:
- 在Vue组件中,为每个输入框(例如income、cost、subtotal和taxExemptIncome)绑定一个数据变量,将输入框的值与这些变量进行双向绑定。
<template>
<div>
<form-item label="收入">
<el-input v-model="income"></el-input>
</form-item>
<form-item label="费用">
<el-input v-model="cost"></el-input>
</form-item>
<form-item label="本期其他扣除(小计)">
<el-input v-model="subtotal"></el-input>
</form-item>
<form-item label="免税收入">
<el-input v-model="taxExemptIncome"></el-input>
</form-item>
<el-button @click="calculateTaxableAmount">计算</el-button>
</div>
</template>
<script>
export default {
data() {
return {
income: '', // 收入
cost: '', // 费用
subtotal: '', // 本期其他扣除(小计)
taxExemptIncome: '', // 免税收入
};
},
methods: {
calculateTaxableAmount() {
const income = parseFloat(this.income);
const cost = parseFloat(this.cost);
const subtotal = parseFloat(this.subtotal);
const taxExemptIncome = parseFloat(this.taxExemptIncome);
const taxableAmount = income - cost - taxExemptIncome - subtotal;
// 将计算结果传递给acTaxableAmount
this.$emit('update:acTaxableAmount', taxableAmount);
},
},
};
</script>
- 在父组件中使用子组件,并将acTaxableAmount绑定到一个数据变量,以接收传递的值。
<template>
<div>
<child-component v-model="acTaxableAmount"></child-component>
<div>应纳税所得额:{{ acTaxableAmount }}</div>
</div>
</template>
<script>
import ChildComponent from './ChildComponent.vue';
export default {
components: {
ChildComponent,
},
data() {
return {
acTaxableAmount: '', // 应纳税所得额
};
},
};
</script>
这样,当用户在子组件中点击"计算"按钮时,会触发calculateTaxableAmount方法,该方法会计算应纳税所得额,并通过$emit将结果传递给父组件的acTaxableAmount变量。父组件会监听acTaxableAmount的变化,并在模板中显示出来。
原文地址: http://www.cveoy.top/t/topic/jgQc 著作权归作者所有。请勿转载和采集!