简体   繁体   English

Vue.js 我如何对打印的值求和

[英]Vue.js how can i sum values i print

I work on a commercial site and when the customer orders a product, I do the following: Printing the price of the product first for example $ 60 Then if the customer chooses the fast shipping service, I print the value of the express shipping service, for example, $20.我在一个商业网站上工作,当客户订购产品时,我会执行以下操作:首先打印产品的价格,例如 60 美元然后如果客户选择快速送货服务,我打印快递服务的价值,例如,20 美元。 How do I addition and print numbers in Total?如何在 Total 中添加和打印数字?

<ul>
    <li>Price : {{product.product_price}} Doller</li>
    <li v-if="orderData.fastDelivry">Fast delivry : {{delevryValue}} Doller</li>
    <li>Total : </li>
</ul>

Try like following snippet:尝试像下面的片段:

 new Vue({ el: '#demo', data() { return { product: { name: 'prod 1', product_price: 15 }, orderData: { fastDelivry: false }, delevryValue: 5 } }, computed: { total() { return (this.orderData.fastDelivry? this.product.product_price + this.delevryValue: this.product.product_price) } }, methods: { setDelivery() { this.orderData.fastDelivry =.this.orderData.fastDelivry } } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="demo"> <ul> <li>Price: {{product.product_price}} Doller</li> <input type="checkbox" @click="setDelivery" /> fast delivery <li v-if="orderData.fastDelivry">Fast delivry: {{delevryValue}} Doller</li> <li>Total: {{ total }}</li> </ul> </div>

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

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