javascript - Vuejs/Laravel 中的计算机功能出现错误

标签 javascript vue.js

我正在尝试在 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

最佳答案

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

更改为: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/

相关文章:

javascript - vue Typescript,对象数组上的引用

javascript - 如何动态绑定(bind)到:src of img in vue js?

javascript - 如何在 JSX 中格式化日期?

vue.js 结构化应用布局

javascript - 如何开始编写像 mohiomap 这样的东西?

javascript - 如何正确清理timbre.js

javascript - 跟踪数组中添加的元素?

javascript - Vue.js 中 Select 的异常行为

javascript - 在 mvc View 中显示/隐藏文本区域

javascript - 如何通过chrome扩展获取特定页面的 session 数据?