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

Native JS to achieve cool paging effect

This article uses an example to share with you a ...

A brief discussion on CSS3 animation jamming solutions

Why is it stuck? There is a premise that must be ...

Analysis of statement execution order of sql and MySQL

I encountered a problem today: Can I use the as a...

js to realize simple shopping cart function

This article example shares the specific code of ...

How to configure the Runner container in Docker

1. Create a runner container mk@mk-pc:~/Desktop$ ...

CentOs7 64-bit MySQL 5.6.40 source code installation process

1. Install the dependency packages first to avoid...

How to query date and time in mysql

Preface: In project development, some business ta...

Docker port mapping and external inaccessibility issues

The Docker container provides services and listen...

Native JS to achieve drag photo wall

This article shares with you a draggable photo wa...

Tutorial on resetting the root password of Mac MySQL

Disclaimer: This password reset method can direct...

Detailed tutorial of using stimulsoft.reports.js with vue-cli

vue-cli uses stimulsoft.reports.js (nanny-level t...

Docker learning method steps to build ActiveMQ message service

Preface ActiveMQ is the most popular and powerful...