我正在尝试在 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;
}
},
});
错误是我的函数不是计算税额+金额,而是将值设置为税额和金额。 示例:不是 10+5=15,而是 10 5
最佳答案
您需要先将 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;
}
关于javascript - Vuejs/Laravel 中的计算机功能出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53155837/