javascript - 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,而是放置taxamount和Amount之类的值。示例:而不是 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;
}
推荐阅读
- swift - EXC_BAD_ACCESS 和 Address Sanitizer 下一步是什么?
- python - 用 Pandas 重新采样比原始时间范围更长的时间
- python - 如何匹配后面没有空格的数字字符
- javascript - JS 中的词法作用域
- scala - Scala - 使用 foldLeft 有条件地对列表中的元素求和
- node.js - 使用 nodejs/express 登录后将用户重定向到 Angular 应用程序
- node.js - NODE.js 插入 SQL Server
- c# - BayesServer: InvalidNetworkException: Node [Knowledge] 有一个空分布
- jquery - 选中时获取单选按钮的值
- php - 通过 API 检索有关 Google Play 应用内购买订阅的信息