Get the App
SLTechnology News&Howtos  ›  Development  › 

If vue implements the function of shopping cart

Shulou Source: shulou.com Published: 2022-06-01 07:02:15 10月06日 Update

In this article, the editor introduces in detail "vue if shopping cart function", the content is detailed, the steps are clear, and the details are handled properly. I hope this "vue if shopping cart function" article can help you solve your doubts.

Principle analysis and implementation

Note that in order to achieve this function, you need to learn: Vue learning path (basic article), in-depth understanding of the use of each instruction

First of all, let's first write the layout, and introduce vue to prepare the vue instance, not to mention this, the code is as follows

Vue implements Shopping cart

Shopping Cart

Name:

Unit price:

Quantity:

Add shopping cart

Name

Unit price

Quantity

Subtotal

{{product.name}}

{{product.price}}

-

{{product.count}}

+

{{product.price*product.count}}

Total price: {{total ()}} yuan

New Vue ({

El: "# app"

Data: {

Products: [

{name: "long johns", price: "81", count: 2}

{name: "Huawei", price: "5810", count: 1}

]

NameValue: ""

PriceValue: ""

CountValue: 0

TotalPrice:0

}

Methods: {

Incr (index) {

This.products [index] .count + +

}

Desc (index) {

This.products [index] .count--

}

Add () {

This.products.push ({name: this.nameValue, price: this.priceValue, count: this.countValue})

This.nameValue = ""

This.priceValue = ""

This.countValue = 0

}

Total () {

Var price=0

For (var I = 0; I

Tags: Shopping cart shopping function article learning content unit price name quantity appropriateness code principle foundation example layout idea total price instruction new knowledge more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB vpn Docker Shulou Technology