Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vuejs2 Vue 2-计算输入的行总数_Vuejs2 - Fatal编程技术网

Vuejs2 Vue 2-计算输入的行总数

Vuejs2 Vue 2-计算输入的行总数,vuejs2,Vuejs2,我有一个带有数量和价格输入的动态表,我使用computed属性来计算每行的总数。 现在我需要找到一种方法来计算总计(所有小计的总和) HTML: 我用一把小小提琴把事情弄清楚 我希望一些指导能帮助我。 先谢谢你 total() { return this.items.reduce((total, item) => { return total + item.qty * item.price; }, 0); } 工作提琴:谢谢,但是如果我想添加数字格式,例如货币格式,该怎

我有一个带有数量和价格输入的动态表,我使用computed属性来计算每行的总数。 现在我需要找到一种方法来计算总计(所有小计的总和)

HTML:

我用一把小小提琴把事情弄清楚

我希望一些指导能帮助我。 先谢谢你

total() {
  return this.items.reduce((total, item) => {
    return total + item.qty * item.price;
  }, 0);
}

工作提琴:

谢谢,但是如果我想添加数字格式,例如货币格式,该怎么办?@Jazuly这个问题似乎与这个问题无关,所以请将它作为一个新问题发布。
computed: {
    subtotalRow() {
      return this.items.map((item) => {
        return Number(item.qty * item.price)
      });
    },
    // the index part is confusing me
    //
    // total() {
    //  return this.items.reduce((total, ?) => {
    //    return total + ?;
    //  }, 0);
    //}
},
total() {
  return this.items.reduce((total, item) => {
    return total + item.qty * item.price;
  }, 0);
}