html表格填数字自动求和,vue原生table表格,输入数值求和

标签:

实现的是用vue项目实现原生的table求一列的数值总和,其中数值是后期通过input输入的

html代码

ID名称数学物理英语手动打分

{{item.id}}{{item.name}}{{item.amount1}}{{item.amount2}}总计N/A{{sumAmount}}{{sumMoney}}

{{sunCount}}

没放样式代码了, 这里只实现功能

js代码

var Main = {

data() {

return {

tableData6: [{

id: '12987122',

name: '王小虎111',

amount1: '234',

amount2: '3.2',

amount3: 10,

amount4: ''

}, {

id: '12987123',

name: '王小虎222',

amount1: '165',

amount2: '4.43',

amount3: 12,

amount4: ''

}, {

id: '12987124',

name: '王小虎333',

amount1: '324',

amount2: '1.9',

amount3: 9,

amount4: ''

}, {

id: '12987125',

name: '王小虎444',

amount1: '621',

amount2: '2.2',

amount3: 17,

amount4: ''

}, {

id: '12987126',

name: '王小虎555',

amount1: '539',

amount2: '4.1',

amount3: 15,

amount4: ''

}],

};

},

computed: {

sumAmount() {

return this.tableData6.map(row => row.amount1).reduce((acc, cur) => (parseInt(cur) + acc), 0)

},

sumMoney() {

return this.tableData6.map(row => row.amount2).reduce((acc, cur) => (parseFloat(cur) + acc), 0)

},

// 方法一:计算属性

sunCount() {

console.log('this.tableData6.map(row => row.amount4)', this.tableData6.map(row => row.amount4))

var bb = [];

for(var i in this.tableData6.map(row => row.amount4)){

if(this.tableData6.map(row => row.amount4)[i]) {

bb.push(this.tableData6.map(row => row.amount4)[i])

}

}

return bb.reduce((acc, cur) => (parseFloat(cur) + acc), 0)

// return this.tableData6.map(row => row.amount4).reduce((acc, cur) => (parseFloat(cur) + acc), 0)

// let num = 0

// for( let i = 0 ; i < this.tableData6.length ; i++) {

// num += Number(this.tableData6[i].amount4)

// }

// return num

}

},

methods: {

// 方法二: 通过change事件实现

// blurInput(index) {

// console.log('index', this.tableData6)

// let num = 0;

// this.tableData6[index].amount4 = number

// for( let i = 0 ; i < this.tableData6.length ; i++) {

// num += Number(this.tableData6[i].amount4)

// }

// this.englishAllNum = num

// },

}

};

var Ctor = Vue.extend(Main)

new Ctor().$mount('#app')

标签:

来源: https://www.cnblogs.com/lxk0301/p/10161359.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值