Vue implements a simple shopping cart example

Vue implements a simple shopping cart example

This article shares the specific code of Vue to implement a simple shopping cart case for your reference. The specific content is as follows

Code:

<template>
  <div>
    <div>
      <span>Mobile: </span>
      <span>Price</span> <input type="number" v-model.number="phonePrice">
      <span> Quantity</span><input type="number" v-model.number="phoneCount">
      <span>Subtotal: </span><span>{{phoneTotal}} yuan</span>
    </div>
    <div>
      <span>Computer: </span>
      <span>Price</span> <input type="number" v-model.number="computerPrice">
      <span> Quantity</span><input type="number" v-model.number="computerCount">
      <span>Subtotal: </span><span>{{computerTotal}} yuan</span>
    </div>
    <div>
      <span>Shipping fee: </span><input type="number" v-model.number="freight"><span>Yuan</span><br>
      <span>Total: {{total}} yuan</span>
      <p>Discount: {{discounts}} yuan</p>
      <p>Payable: {{allPrice}}</p>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      phonePrice: '', // price of a phone phoneCount: '', // number of phones computerPrice: '', // price of a computer computerCount: '', // number of computers frequency: '', // freight discounts: ''
    }
  },
  computed: {
    phoneTotal() {
      return this.phonePrice * this.phoneCount
    },
    computerTotal() {
      return this.computerPrice * this.computerCount
    },
    //Total price total () {
      return this.computerTotal + this.phoneTotal + this.freight
    },
    allPrice() {
      return this.total - this.discounts
    }
  },
  watch:
    total:
      depp: true,
      handler () {
        if (this.phoneTotal + this.computerTotal > 5000 && this.phoneTotal + this.computerTotal < 8000) {
          this.discounts = 100
        } else if (this.phoneTotal + this.computerTotal > 8000) {
          this.discounts = 200
        }
      }
    }
  }
}
</script>

<style scoped lang='less'>
</style>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vuejs teaches you step by step to write a complete shopping cart example code
  • Implementing shopping cart function based on Vuejs
  • Vue implements shopping cart function
  • Vue implements a small case of shopping cart
  • Vue realizes the shopping cart function of the mall
  • Vue realizes shopping cart total price calculation
  • Simple shopping cart function example implemented by vuex
  • vue+vant-UI framework realizes the checkbox selection and deselection function of the shopping cart
  • Detailed explanation of how to use Vue to achieve the parabolic ball animation effect in the shopping cart
  • Detailed explanation of the shopping cart function implemented by Vue.js

<<:  Nginx builds rtmp live server implementation code

>>:  Implementation of proxy_pass in nginx reverse proxy

Recommend

Docker time zone issue and data migration issue

Latest solution: -v /usr/share/zoneinfo/Asia/Shan...

Differences in the hr separator between browsers

When making a web page, you sometimes use a dividi...

How to install Odoo12 development environment on Windows 10

Preface Since many friends say they don’t have Ma...

How to build sonarqube using docker

Table of contents 1. Install Docker 2. Install so...

Vue3.0 uses the vue-grid-layout plug-in to implement drag layout

Table of contents 1. Plugins 2. Interlude 3. Impl...

Detailed explanation of the background-position percentage principle

When I was helping someone adjust the code today,...

Implementation of Docker CPU Limit

1. --cpu=<value> 1) Specify how much availa...

Vue implements three-dimensional column chart based on echarts

The three-dimensional column chart consists of th...

Examples of using html unordered list tags and ordered list tags

1. Upper and lower list tags: <dl>..</dl...

Using MySQL in Windows: Implementing Automatic Scheduled Backups

1. Write a backup script rem auther:www.yumi-info...

Detailed explanation of MySQL batch SQL insert performance optimization

For some systems with large amounts of data, the ...

Solution to secure-file-priv problem when exporting MySQL data

ERROR 1290 (HY000) : The MySQL server is running ...