首页 > 解决方案 > Vuejs / Laravel中的计算机功能错误

问题描述

我正在尝试在 Laravel 应用程序中使用 Vuejs 输入后计算总税额。我的计算机计算总数的功能不起作用。我错过了哪里?

这是我的 vuejs 代码:

var app = new Vue({
el: '#app',
data: {
rinvoices: {    
        amount:'',
        tva:'',        
},
},
 methods: {
        addRinvoice: function () {
        axios.post('/addrinvoice', this.rinvoices)
            .then(response => {
                console.log(response.data);
                if (response.data.etat) {
                    this.rinvoices = {
                         id: 0,
                          amount: response.data.etat.amount,
                           tva: response.data.etat.tva,     
                    };
                }

            })
    },
    },
computed: {
total: function () {
    var amount= this.rinvoices.amount;
    var tax= this.rinvoices.tva;
    var taxamount= amount*tax;
    var t=taxamount + amount;
    return t;
}
},
});

错误是我的功能不是计算taxamount + amount,而是放置taxamountAmount之类的值。示例:而不是 10+5=15 它是 10 5

标签: javascriptvue.js

解决方案


您需要先将taxamount&amount从字符串转换为数字,然后再进行加法。

改成:var t = +taxamount + +amount;

total: function () {
   var amount= this.rinvoices.amount;
   var tax= this.rinvoices.tva;
   var taxamount= amount*tax;
   var t = +taxamount + +amount;
   return t;
}


推荐阅读