在vuejs2中求和值

时间:2019-02-23 18:46:12

标签: vue.js vuejs2

嗨,我有这个vuejs2代码

totals() {
    this.total = 0;
    console.log(this.total_without_discount);
    console.log(this.total_taxs);
    console.log(this.total_discount);
    this.total += this.total_without_discount;
    this.total += this.total_taxs;
    this.total += this.total_discount;
    return Number(this.total).toFixed(this.comma);
},

现在,当我得到结果后,我就回到南 所有这些功能都在computed中 我如何将合计函数中的值求和并将其返回 谢谢

1 个答案:

答案 0 :(得分:1)

根据所需的数据类型和精度,使用parseIntparseFloat

totals() {
    this.total = 0;

    this.total += parseFloat(this.total_without_discount);
    this.total += parseFloat(this.total_taxs);
    this.total += parseFloat(this.total_discount);

    return parseFloat(this.total).toFixed(this.comma);
},