This article mainly introduces the use of vue2 to implement shopping cart and address selection functions. This article introduces it to you in great detail through a combination of example codes. Friends in need can refer to it
First of all, vue basic js writing method
new Vue({ el:"#app", //模型 data:{ }, filters:{ }, mounted:function(){ this.$nextTick(function(){ //初始化调用 }); }, computed:{ //实时计算 }, methods:{ } });
v-for
<li v-for="(item,index) in productList"> <p class="item-name">{{item.productName}}</p> </li>
v-model
(Real-time update)
<input type="text" value="0" disabled v-model="item.productQuantity"> <p class="item-price-total">{{item.productQuantity}}</p>
v-bind
<a href="javascript:;" class="item-check-btn" v-bind:class="{'check':item.checked}"> <!--可通过更改item.checked的值设置是否选中--> <!--必须用v-bind 不可直接在class里面直接使用{{}}--> <!--v-bind:class= 可简写为 :class= -->
Usage of filters
1.html reference method
<p class="item-price">{{item.productPrice | money('元')}}</p>
2. Filter
filters:{ formatMoney:function(value,type){ return "¥"+value.toFixed(2)+ type; } },
3.Global filter (written in new Outside 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
is as follows: Three pieces of data are displayed by default, click more to display all
<li v-for="(item,index) in filterAddress"> <p class="shipping-addr-more"> <a class="addr-more-btn up-down-btn" href="javascript:" @click="limitNum=addressList.length"> more <i class="i-up-down"> <i class="i-up-down-l"></i> <i class="i-up-down-r"></i> </i> </a> </p> data:{ limitNum:3 }, computed:{ filterAddress:function(){ return this.addressList.slice(0,this.limitNum); } },
First put forward one or two classic examples
1. The following implements the click selection of the loop card
<li v-for="(item,index) in filterAddress" v-bind:class="{'check':index==currentIndex}" @click="currentIndex=index"> <!--其中currentIndex在js里需要定义-->
2. The following implements the click selection of the fixed card
<ul> <li v-bind:class="{'check':shippingMethod==1}" @click="shippingMethod=1"> <p class="name">标准配送</p> <p class="price">Free</p> </li > <li v-bind:class="{'check':shippingMethod==2}" @click="shippingMethod=2"> <p class="name">高级配送</p> <p class="price">180</p> </li> </ul> <!--其中shippingMethod在js里需要定义-->
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 class="md-overlay" v-if="delFlag"></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.forEach Loop
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);//全局注册 } });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Angular 5.x Study Notes Router (routing) application
##vue2.0 resource file assets and static Detailed explanation of the difference
vuex project structure directory and some simple configuration introduction
The above is the detailed content of Use vue2 to implement shopping cart and address selection functions. For more information, please follow other related articles on the PHP Chinese website!

地址解析协议 (ARP) 用于将 MAC 地址映射到 IP 地址。网络上的所有主机都有自己的 IP 地址,但网络接口卡 (NIC) 将有 MAC 地址而不是 IP 地址。ARP 是用于将 IP 地址与 MAC 地址相关联的协议。所有这些条目都被收集并放置在 ARP 缓存中。映射的地址存储在缓存中,它们通常不会造成任何损害。但是,如果条目不正确或 ARP 缓存损坏,则会出现连接问题、加载问题或错误。因此,您需要清除 ARP 缓存并修复错误。在本文中,我们将研究如何清除 ARP 缓存的不同方法。方法

任何连接到互联网的设备都有两种类型的地址——物理地址和互联网地址。虽然 Internet 地址在全球范围内定位设备,但物理地址有助于识别连接到本地网络的特定设备。这个物理地址在技术上称为 MAC 地址,如果您想知道您的 iPhone 是否有一个,是的,所有手机(包括 iPhone)都有自己独有的 MAC 地址。什么是 MAC 地址?媒体访问控制或 MAC 地址是一种独特的指标,用于从连接到同一网络的其他设备中识别您的设备。如果您拥有可以连接到互联网的设备,它将注册一个 MAC 地址。此地址由占

为什么我需要在Windows11中分配辅助IP地址?现在,我们来到最重要的问题,为什么您需要在Windows11中分配一个辅助IP地址甚至多个?假设您有一台具有默认IP地址的设备并且想要使用另一台设备,这可能需要添加一个辅助设备。除此之外,它还用于托管各种SSL网站。如果您必须在短时间内发送大量电子邮件,获取多个IP地址可能会有所帮助,因为在特定时间范围内可以从一个IP地址发送多少是有限制的。此外,一些用户对其进行了设置,以避免被列入垃圾邮件过滤器的黑名单。此外,添加辅

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

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

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

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

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


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

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

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.

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