【问题标题】:Why Can't I See My GrandTotal In My View?为什么在我的视图中看不到我的总计?
【发布时间】:2019-04-01 15:00:46
【问题描述】:

我正在使用Laravel 5.7 & VueJs 2.5.* ...

我想在我的视图表上显示GrandTotal,但我不知道我做错了什么。

我在哪里显示GrandTotal

<tr v-for="ctInvoice in ctInvoices" :key="ctInvoice.id">
  <td>{{ formatPrice(ctInvoice.ct_invoice_grand_total) }}</td>
</tr>

我的VueJsdata()

data() {
    return {
      ctInvoices: {},
      customers: null,
      form: new Form({
        id: "",
        customer_id: "",
        ct_invoice_no: "",
        ct_invoice_date: "",
        ct_invoice_fares_total: 0,
        ct_invoice_taxes_grand_total: 0,
        ct_invoice_grand_total: 0,

        ctInvoiceItems: [{
          id: "",
          ct_invoice_id: "",
          ct_passenger_name: "",
          ct_fares: 0,
          ct_total_tax_breakup: 0,
          ct_sub_total: 0
        }]
      })
    };

使用此method() 格式化金额:

formatPrice(value) {
  let val = (value / 1).toFixed().replace(".", ".");
  return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //75.674,00
},

图片便于理解:

ctInvoices 数组的一项输出

ctInvoices:数组[20] 0:对象 created_at:"2018-10-27 15:13:06" ct_Invoice_date:"2018-10-31" ct_Invoice_fares_total:"600.00" ct_Invoice_grand_total:"1000.00" ct_Invoice_grand_total_words:空 ct_Invoice_taxes_grand_total:"400.00" ct_Invoice_terms:空 ct_invoice_items:Array1 ct_invoice_no:"111-222-333" 客户:对象 客户 ID:3 编号:22 更新时间:“2018-10-27 15:13:06”

【问题讨论】:

  • 你为什么要replace(".", ".");
  • 我不知道我只是想以金钱的形式展示我的价值,所以我提出了问题,一个人给了我formatMoneymethod()
  • 你能给我介绍一下那个问题吗?
  • @BoussadjraBrahim 在这里,stackoverflow.com/questions/43208012/…
  • 在你的情况下你正在做let val = (value / 1).toFixed().replace(".", ".");,但在给定的问题中有let val = (value / 1).toFixed().replace(".", ",");

标签: javascript html laravel vue.js vuejs2


【解决方案1】:

你打错了,你的 ctInvoice 对象中有一个名为 ct_Invoice_grand_total 的属性,大写 I 并且你用小写 i 调用它,所以你应该输入:

     <tr v-for="ctInvoice in ctInvoices" :key="ctInvoice.id">
       <td>{{ formatPrice(ctInvoice.ct_Invoice_grand_total) }}</td>
     </tr>

【讨论】:

    【解决方案2】:

    您的控制台显示什么错误?

    在您的数据中,您将ctInvoices 指定为一个对象,这不应该是一个包含ctInvoice 对象的数组吗?

    ctInvoices 中的每个ctInvoice 是否都包含一个ct_invoice_grand_total 属性?

    您可以使用带有toLocaleString 的过滤器,而不是使用函数来格式化价格。

    Vue.filter('formatNumber', value => {
        let number = parseFloat(value);
        let options = { minimumFractionDigits: 2, style: 'currency', currency: 'EUR' };
    
        return number.toLocaleString("nl-NL", options);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2012-03-23
      • 1970-01-01
      • 2022-07-11
      • 2020-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多