vue+表格某一行做统计(包括小数)

好久没更新了,最近这阵子被拉去写后端代码了,现在才终于重新碰前端的东西,结果就手生了,之前会写的现在卡了半天,最后还是忍不住去看了我之前的代码咋写的……记录一下防止下次又忘记

效果如下:

不使用表格总计行,而是在表格上面单写一个input,实时计算数据。

解法:

computed计算属性

amountTotal(){
        let sum = 0;
        if(this.gdsTableList){
          this.gdsTableList.forEach((item)=>{
            sum += Number(item.amount) || Number(0)
          })
        }
        return sum
      },

如果想保留小数什么的,也可以,加上相应的限制就好了,如下:

computed:{
      taxTotalFee(){
        let sum = 0;
        if(this.gdsTableList){
          this.gdsTableList.forEach((item)=>{
            sum += Number(item.taxFee) || Number(0)
          })
          sum = pars
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue 3和TypeScript中实现表格某一列的字典匹配,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Vue 3和TypeScript,以及相关的依赖。 2. 在Vue组件中定义表格数据和字典数据。你可以使用`ref`来声明响应式的变量,并将其初始化为空数组或空对象。 ```typescript import { defineComponent, ref } from 'vue'; export default defineComponent({ setup() { const tableData = ref([]); const dictionaryData = ref({}); // 获取表格数据和字典数据的方法,可以从后端接口获取或其他方式 const fetchTableData = () => { // ... }; const fetchDictionaryData = () => { // ... }; // 在组件初始化时获取表格数据和字典数据 fetchTableData(); fetchDictionaryData(); return { tableData, dictionaryData, } }, }); ``` 3. 在获取到表格数据和字典数据后,你可以使用计算属性来进行字典匹配,并返回处理后的表格数据。 ```typescript import { computed } from 'vue'; // ... export default defineComponent({ // ... computed: { processedTableData() { return computed(() => { return this.tableData.value.map((row: any) => { const gender = row.gender; const matchedValue = this.dictionaryData.value[gender] || ''; return { ...row, gender: matchedValue }; }); }); }, }, }); ``` 4. 在模板中渲染处理后的表格数据。 ```html <template> <table> <thead> <tr> <th>ID</th> <th>Name</th> <th>Gender</th> </tr> </thead> <tbody> <tr v-for="row in processedTableData" :key="row.id"> <td>{{ row.id }}</td> <td>{{ row.name }}</td> <td>{{ row.gender }}</td> </tr> </tbody> </table> </template> ``` 通过以上步骤,你可以在Vue 3和TypeScript中实现表格某一列的字典匹配。请根据实际情况修改示例代码中的变量名、数据获取方法和具体逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值