


Example analysis on functions such as full selection and inverse selection of shopping cart checkbox in Vue
This article mainly shares with you an example analysis of Vue's shopping cart checkbox full selection and inverse selection functions. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor and take a look.
Since the logic is relatively simple, I will attach the code directly! Hope you can pick more~~~~
html code:
<p class="select-buyer"> <checklist :options="fullValues"></checklist> <span>id: {{selectedData}}</span> <p class="weui-cells weui-cells_checkbox"> <label v-for='(item, index) in checkboxData' :key="item.id" class="weui-cell weui-check_label"> <p class="weui-cell__hd"> <input :value="item.id" v-model="checkBox.items[index]" @click="handleInputChange" type="checkbox" name="vux-checkbox" class="weui-check"> <i class="weui-icon-checked vux-checklist-icon-checked"></i> </p> <p class="weui-cell__bd"> <p>{{item.value}}价格:{{item.price}}</p> </p> </label> </p> </p>
.Vue file code:
<template src="./index.html"></template> <script> import { Checklist } from "vux"; export default { name: "selectBuyer", data() { return { fullValues: [], checkboxData: [ { id: "1", value: "苹果4S", price: 110 }, { id: "2", value: "苹果5C", price: 250 }, { id: "3", value: "苹果6P", price: 340 } ], selectedData: [], totalPrice: 0.00, isAllChecked: true, checkBox: { checked: false, items: {} } }; }, mounted() { this.checkboxData.forEach((item, index) => { this.selectedData.push(item.id); this.$set(this.checkBox.items, index, !this.checkBox.checked); }); }, computed: { totalPurchasers() { return this.selectedData.length; }, calculatedTotal() { this.totalPrice = 0.00; this.selectedData.map((item1, index) => { let curItem1 = item1; this.checkboxData.map((item2, index) => { if(this.checkboxData[index].id == curItem1){ this.totalPrice += this.checkboxData[index].price; } }); }); return this.totalPrice; } }, methods: { //全选点击事件 checkedAll() { let trueNum = 0; let checkBoxNum = 0; Object.keys(this.checkBox.items).forEach(key => { checkBoxNum++; if (this.checkBox.items[key] === true) { trueNum++; } }); if (trueNum != 0) { if ( trueNum != this.checkboxData.length || checkBoxNum < this.checkboxData.length ) { this.checkboxDataMap(!this.checkBox.checked); } else { this.checkboxDataMap(this.checkBox.checked); } } else { this.checkboxDataMap(!this.checkBox.checked); } }, //遍历改变checkbox状态 checkboxDataMap(checked) { let checkboxDataId = []; this.checkboxData.forEach((item, index) => { this.checkBox.items[index] = checked; checkboxDataId.push(item.id); }); if (checked == true) { this.selectedData = this.arrayMerging( this.selectedData, checkboxDataId ); } else { this.selectedData.splice(0, this.selectedData.length); } }, //input输入框change事件 handleInputChange(e) { setTimeout(() => { if (this.selectedData.indexOf(e.target.value) > -1) { this.remove(this.selectedData, e.target.value); } else { this.selectedData.push(e.target.value); } if (this.selectedData.length < this.checkboxData.length) { this.isAllChecked = false; } else { this.isAllChecked = true; } }, 0); }, //数组删除 remove(arr, val) { var index = arr.indexOf(val); if (index > -1) { arr.splice(index, 1); } }, //数组合并去重 arrayMerging(arr1, arr2) { var arr = arr1.concat(); for (var i = 0; i < arr2.length; i++) { if (arr.indexOf(arr2[i]) === -1) { arr.push(arr2[i]); } } return arr; } }, components: { Checklist }, metaInfo() { return { title: "选择购卡学生" }; } }; </script> <style src="./index.less" lang="less"></style>
less style file:
@import (reference) "../../style/common.less"; .select-buyer { .weui-cells_checkbox { margin-top: -25px !important; font-size: 28px; .weui-cell { padding: 40px 30px !important; .vux-label-desc { font-size: inherit; } } & .weui-icon-checked:before { font-size: 48px; } & .weui-check:checked+.vux-checklist-icon-checked:before { color: @g-main-green; } } .footer .weui-cells_checkbox .weui-check:checked+.weui-icon-checked:before { content: '\EA01'; } .footer .weui-cells_checkbox .weui-check:checked+.vux-checklist-icon-checked:before { color: #C9C9C9; } } .pay-area { position: fixed; height: 94px; background-color: @g-white; display: flex; width: 100%; left: 0; bottom: 0; .pay-btn { width: 220px; text-align: center; font-size: 36px; /* px */ line-height: 94px; color: @g-white; background-color: @g-main-green; .loading-img { width: 40px; vertical-align: -3px; margin: 0 3px; } } .pay-text { font-size: 28px; color: @g-font-default-color; line-height: 54px; /* px */ display: inline-block; vertical-align: top; margin-right: 10px; } .pay-money { font-size: 48px; /* px */ line-height: 54px; /* px */ color: @g-font-dark-color; } .price-area { flex: 1; padding: 20px 30px; } } .error { padding-left: 15px; line-height: 28px; color: #888; font-size: 12px; }
Related recommendations:
Vue.js implements full selection and inverse selection of checkbox
Three ways to implement full selection and inverse selection of checkbox
Implementation of full selection and inverse selection effects in checkbox in js
The above is the detailed content of Example analysis on functions such as full selection and inverse selection of shopping cart checkbox in Vue. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



We often hear the operation of inverting selection in many graphic editing software. Can we achieve inverse selection in word documents? In fact, the functions of the Word office software are relatively powerful. Even if there is no direct inverse selection tool that can reverse the selection of content with one click, we can also use alternative methods to complete the reverse selection in Word. If you encounter the operation requirement of reverse selection in Word at work, Come here quickly to see how to reverse the selection in word. 1. First, we create and open a word document, and we need to enter some text content. 2. We select part of the text and set its font color to red, as shown in the figure below: 3. Below, we find [Search] on the toolbar, pull down and click the [Advanced Search] option, and then search and replace

How to implement a simple shopping cart function in Java? The shopping cart is an important feature of an online store, which allows users to add items they want to purchase to the shopping cart and manage the items. In Java, we can implement a simple shopping cart function by using object-oriented approach. First, we need to define a product category. This class contains attributes such as product name, price, and quantity, as well as corresponding Getter and Setter methods. For example: publicclassProduct

In our daily lives, online shopping has become a very common way of consumption, and the shopping cart function is also one of the important components of online shopping. So, this article will introduce how to use PHP language to implement shopping cart related functions. 1. Technical background The shopping cart is a common function on online shopping websites. When users browse some products on a website, they can add those items to a virtual shopping cart for easy selection and management during the subsequent checkout process. A shopping cart usually includes the following basic functions: Add items:

PHP mall development skills: Design shopping cart and order synchronization functions In a mall website, shopping cart and orders are indispensable functions. The shopping cart is used for users to purchase products and save them to a temporary shopping cart, while the order is a record generated after the user confirms the purchase of the product. In order to improve user experience and reduce errors, it is very important to design a shopping cart and order synchronization function. 1. The Concept of Shopping Cart and Order A shopping cart is usually a temporary container used to store items purchased by users. Users can add products to the shopping cart for easy browsing and management.

How to use Redis and JavaScript to implement the shopping cart function. The shopping cart is one of the very common functions in e-commerce websites. It allows users to add items of interest to the shopping cart, making it convenient for users to view and manage purchased items at any time. In this article, we will introduce how to implement the shopping cart function using Redis and JavaScript, and provide specific code examples. 1. Preparation Before starting, we need to ensure that Redis has been installed and configured, which can be done through the official website [https:/

Practical tutorial: Detailed explanation of the shopping cart function with PHP and MySQL. The shopping cart function is one of the common functions in website development. Through the shopping cart, users can easily add the goods they want to buy to the shopping cart, and then proceed with settlement and payment. In this article, we will detail how to implement a simple shopping cart function using PHP and MySQL and provide specific code examples. To create a database and data table, you first need to create a data table in the MySQL database to store product information. The following is a simple data table

How to design the shopping cart table structure of the mall in MySQL? With the rapid development of e-commerce, shopping carts have become an important part of online malls. The shopping cart is used to save the products purchased by users and related information, providing users with a convenient and fast shopping experience. Designing a reasonable shopping cart table structure in MySQL can help developers store and manage shopping cart data effectively. This article will introduce how to design the shopping cart table structure of the mall in MySQL and provide some specific code examples. First, the shopping cart table should contain

How to use PHP to implement a simple shopping cart function The shopping cart function is an essential part of an e-commerce website. It allows users to add items of interest to the shopping cart, and then proceed to checkout or continue browsing and adding items. This article will introduce how to use PHP to implement a simple shopping cart function and provide specific code examples. Creating the database and tables First, we need to create a database and a table to store the shopping cart data. CREATEDATABASEshopping_ca
