简体   繁体   English

在 vuejs 中求和来自 v-model 的可选值的问题

[英]problem to sum optional values from v-model in vuejs

in this function i want to show what left from amount在这个 function 我想展示剩下的金额

 remainingAmount: function() {
            return parseFloat(this.sumAmount) - (parseFloat(this.cash) + parseFloat(this.kNet) + parseFloat(this.kNetOnline));
        }

three parameter cash and knet and knet online are came from v-model, if one of them be null retuen result being NAN?三个参数cash和knet和knet online是来自v-model,如果其中一个是null返回结果是NAN? how can i defined these v-model as optional in this function?我如何在这个函数中将这些 v-model 定义为可选?

i can not find any optional function in js so i solved with conditions:我在 js 中找不到任何可选的 function 所以我解决了条件:

            var a = this.cash ?  parseFloat(this.cash) :0
            var b = this.kNetOnline ?  parseFloat(this.kNetOnline) :0
            var c = this.kNet ?  parseFloat(this.kNet) :0

but i think is not working for large scale data但我认为不适用于大规模数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM