


This time I will bring you a detailed explanation of the steps to implement shopping cart and address selection in vue2. What are the precautions for implementing the shopping cart and address selection steps in vue2. The following is a practical case. Let’s take a look. .
First of all, vue basic js writing method
new Vue({ el:"#app", //模型 data:{ }, filters:{ }, mounted:function(){ this.$nextTick(function(){ //初始化调用 }); }, computed:{ //实时计算 }, methods:{ } });
v-for
{{item.productName}}
v-model
(Real-time update)
<input> <p>{{item.productQuantity}}</p>
v-bind
<a> <!--可通过更改item.checked的值设置是否选中--> <!--必须用v-bind 不可直接在class里面直接使用{{}}--> <!--v-bind:class= 可简写为 :class= --></a>
filtersUse of filters
1.html reference method
<p>{{item.productPrice | money('元')}}</p>
2.Filter
filters:{ formatMoney:function(value,type){ return "¥"+value.toFixed(2)+ type; } },
3. Global filter (written outside new Vue)
Vue.filter("money",function(value,type){ return "¥"+value.toFixed(2) + type; //保留两位小数 结果eg:¥19.00元 });
Call the method in methods:
@click="method(param)" //或者 @click="delFlag=false" @click="limitNum=addressList.length"
computed real-time calculation
are as follows: three pieces of data are displayed by default, click more to display all
Let’s first put forward one or two classic examples
1. The following implements the click selection of the loop card
2. The following implements the click selection of the fixed card
-
标准配送
Free
>
-
高级配送
180
Digression: Since I am a novice, I will learn a little bit, and I will also record the writing method of the auxiliary pop-up box mask layer
<p></p>
#vue2’s js syntax is posted for easy reference
1. Call the backend method
var _this = this; this.$http.get("data/address.json").then(function(response){ _this.addressList = response; //这里不能直接用this 此this非彼this 所以只能声明_this }); //以下为ES6写法,就可以直接用this了 let _this = this; //没用,就放这看看~ this.$http.get("data/cartData.json",{"id":123}).then(res=>{ this.productList = res.data.result.list; });
2.forEachLoop
this.productList.forEach(function(item,index){ if(typeof item.checked == 'undefined'){ //如果item中没有checked属性 在item对象中添加checked属性,值为true _this.$set(item,"checked",true);//局部注册 Vue.set(item,"checked",true);//全局注册 } });
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Detailed explanation of the steps to implement Observer in Vue
Summary of vue parent component calling child component methods
Detailed explanation of the steps to use vue global and local components
The above is the detailed content of Detailed explanation of the steps to implement shopping cart and address selection in vue2. For more information, please follow other related articles on the PHP Chinese website!

vue2与vue3中生命周期执行顺序区别生命周期比较vue2中执行顺序beforeCreate=>created=>beforeMount=>mounted=>beforeUpdate=>updated=>beforeDestroy=>destroyedvue3中执行顺序setup=>onBeforeMount=>onMounted=>onBeforeUpdate=>onUpdated=>onBeforeUnmount=&g

Java中如何实现一个简单的购物车功能?购物车是在线商店的一个重要功能,它允许用户将想要购买的商品添加到购物车中,并对商品进行管理。在Java中,我们可以通过使用面向对象的方式来实现一个简单的购物车功能。首先,我们需要定义一个商品类。该类包含商品的名称、价格和数量等属性,以及相应的Getter和Setter方法。例如:publicclassProduct

在我们日常生活中,网上购物已经成为非常普遍的消费方式,而购物车功能也是网上购物的重要组成部分之一。那么,本文将为大家介绍如何利用PHP语言来实现购物车的相关功能。一、技术背景购物车是一种在线购物网站常见的功能。当用户在一个网站上浏览一些商品,他们可以将这些商品添加到一个虚拟的购物车中,以便于在后续的结账过程中选择和管理。购物车通常包括以下基本功能:添加商品:

diff算法是一种通过同层的树节点进行比较的高效算法,避免了对树进行逐层搜索遍历。那么大家对diff算法吗有多少了解?下面本篇文章就来带大家深入解析下vue2的diff算法,希望对大家有所帮助!

PHP商城开发技巧:设计购物车和订单同步功能在一个商城网站中,购物车和订单是不可或缺的功能。购物车用于用户选购商品并保存到临时购物车中,而订单则是用户确认购买商品后生成的记录。为了提升用户体验和减少错误,设计一个购物车和订单同步的功能非常重要。一、购物车和订单的概念购物车通常是一个临时的容器,用于保存用户选购的商品。用户可以将商品加入购物车,方便浏览和管理。

如何利用Redis和JavaScript实现购物车功能购物车是电商网站中非常常见的功能之一,它允许用户将感兴趣的商品添加到购物车中,方便用户随时查看和管理购买的商品。在本文中,我们将介绍如何利用Redis和JavaScript实现购物车功能,并提供具体的代码示例。一、准备工作在开始之前,我们需要确保已经安装并配置好Redis,可以通过官方网站[https:/

如何在MySQL中设计商城的购物车表结构?随着电子商务的快速发展,购物车已成为在线商城的重要组成部分。购物车用于保存用户选购的商品和相关信息,为用户提供方便快捷的购物体验。在MySQL中设计一个合理的购物车表结构,可以帮助开发人员有效存储和管理购物车数据。本文将介绍如何在MySQL中设计商城的购物车表结构,以及提供一些具体的代码示例。首先,购物车表应该包含以

如何使用PHP实现一个简单的购物车功能购物车功能是电子商务网站中必不可少的一部分,它允许用户将感兴趣的商品添加到购物车中,随后可以进行结算或继续浏览和添加商品。本文将介绍如何使用PHP实现一个简单的购物车功能,并提供具体的代码示例。创建数据库和表格首先,我们需要创建一个数据库和一个用于存储购物车数据的表。CREATEDATABASEshopping_ca


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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
