当前位置: 首页 > news >正文

购物建设网站费用谷歌chrome

购物建设网站费用,谷歌chrome,wordpress 最新评论,专业做网站排名公司电话目录 购物车效果展示: 购物车代码: 购物车效果展示: 此项目添加、修改、删除数据的地方都写了浏览器都会把它存储起来 下次运行项目时会把浏览器数据拿出来并在页面展示 Video_20230816145047 购物车代码: 复制完代码&#xff0…

目录

购物车效果展示:

购物车代码:


购物车效果展示:

此项目添加、修改、删除数据的地方都写了浏览器都会把它存储起来

下次运行项目时会把浏览器数据拿出来并在页面展示

Video_20230816145047

购物车代码:

复制完代码,需改下script中引入的vue文件地址;可直接使用

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><div id="app"><div><form action=""> 商品名称:<input type="text" v-model="productName" name="productName">商品单价:<input type="text" v-model="productPrice" name="productPrice"><input type="button" value="添加商品" @click="addProduct"></form></div><ul><li v-for="(pro,index) in productList" :key="index">商品名称:{{pro.productName}}=========商品单价:{{pro.productPrice}}&nbsp;&nbsp;&nbsp;<button type="button" @click="addProToCart(index)">添加到购物车</button><button type="button" @click="deleteProToCart(index)">删除此商品</button></li></ul><cart :cartlist="cartList"></cart></div><template id="cartHtml"><div><table border="1"><tr><td>全选<input type="checkbox" @change="checkActive" id="isCheck"></td><td>商品名称</td><td>商品单价</td><td>商品数量</td><td>商品价格</td></tr><tr v-for="(pro,index) in cartlist" :key="index"><td><input type="checkbox" v-model="pro.active" @change="ziCheck"></td><td>{{pro.productName}}</td><td>{{pro.productPrice}}</td><td><button type="button" @click="reduceProNum(index)">-</button>{{pro.productNum}}<button type="button" @click="addProNum(index)">+</button></td><td>{{pro.productPrice*pro.productNum}}</td></tr><tr><td colspan="3">选中的商品:{{activeNum}}/{{cartlist.length}}</td><td colspan="2">总价格:{{totalPrice}}</td></tr></table></div></template></body>
<script src="../js/vue2.7.js"></script><!--根据自己的vue文件地址填写-->
<script>//创建一个购物车子组件var cart={template:"#cartHtml",props:["cartlist"],methods:{addProNum(index){let product =this.cartlist[index];product.productNum++localStorage.setItem('cartList', JSON.stringify(this.cartlist));},reduceProNum(index){let product =this.cartlist[index];//判断商品数量是否为一if (product.productNum==1) {this.cartlist.splice(index,1)//为一,在数组中删除掉//删除完后把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem('cartList', JSON.stringify(this.cartlist));}else{product.productNum--//减完之后把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem('cartList', JSON.stringify(this.cartlist));}},checkActive(){if(document.getElementById("isCheck").checked){for(var i=0;i<this.cartlist.length;i++){this.cartlist[i].active=true;}//全选为true后把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem('cartList', JSON.stringify(this.cartlist));}else{for(var i=0;i<this.cartlist.length;i++){this.cartlist[i].active=false;}//全选为false后把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem('cartList', JSON.stringify(this.cartlist));}},ziCheck(){//当多选框变化时把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem('cartList', JSON.stringify(this.cartlist));},},computed:{//计算购物车商品总和activeNum(){let activeProductList=this.cartlist.filter(item=>{return item.active})return activeProductList.length;},//计算购物车商品的总价格totalPrice(){let result=0;for(pro of this.cartlist){if(pro.active){result=result+pro.productPrice*pro.productNum}}return result}},updated() {//当多选框都为true全选后的多选框为truevar isActive=this.cartlist.every(c => c.active)if (isActive) {document.getElementById("isCheck").checked=true} else {document.getElementById("isCheck").checked=false}},}let app=new Vue({el:"#app",data() {return {productName:'',productPrice:'',productList:[],cartList:[]}},methods: {addProduct(){let isnameOk=true;let ispriceOk=true;if (this.productName=="") {isnameOk=false}if(isNaN(this.productPrice) || this.productPrice<=0){ispriceOk=false;}if(isnameOk && ispriceOk){//查找新增的商品是否存在商品列表中,如果不存在返回-1let findindex=this.productList.findIndex(item=>{return item.productName==this.productName})//判断商品列表中是否存在新增的商品if(findindex==-1){//把新商品添加到商品列表中this.productList.push({productName:this.productName,productPrice:this.productPrice})//把数据放在浏览器里面把key值设置为productListlocalStorage.setItem('productList', JSON.stringify(this.productList));//添加完表单中的输入框调为空this.productName='';this.productPrice='';}else{alert("此商品已经存在商品列表!")//商品已存在,给出提示}}else{alert("请输入合适的商品名称及单价")}},addProToCart(index){let newproduct=this.productList[index];//根据下标从商品列表里面取出商品//从购物车列表中查找,是否存在新的商品,如果找到返回购物车的商品let product= this.cartList.find(item=>{return item.productName==newproduct.productName})if (product) {//如果有对应的商品则数量加一product.productNum++}else{//没有对应的商品就添加商品到购物车this.cartList.push({productName:newproduct.productName,productPrice:newproduct.productPrice,productNum:1,active:true})//把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem('cartList', JSON.stringify(this.cartList));}},deleteProToCart(index){let isOk=confirm("是否删除此商品!")if(isOk){this.productList.splice(index,1)}//把数据放在浏览器里面把key值设置为productListlocalStorage.setItem('productList', JSON.stringify(this.productList));}},//生命周期钩子,部署完后执行从浏览器中把数据拿出来mounted(){for(pro of JSON.parse(localStorage.getItem("productList"))){this.productList.push({productName:pro.productName,productPrice:pro.productPrice});}for(pro of JSON.parse(localStorage.getItem("cartList"))){this.cartList.push({productName:pro.productName,productPrice:pro.productPrice,productNum:pro.productNum,active:pro.active});}},components:{cart},})
</script>
</html>

文章转载自:
http://dinncoguestimate.ssfq.cn
http://dinncoamphictyonic.ssfq.cn
http://dinnconeuritic.ssfq.cn
http://dinncostraightway.ssfq.cn
http://dinncokinchinjunga.ssfq.cn
http://dinncosynesthetic.ssfq.cn
http://dinncopraelector.ssfq.cn
http://dinncodisincorporate.ssfq.cn
http://dinncokaunas.ssfq.cn
http://dinncoalthorn.ssfq.cn
http://dinncononnegotiable.ssfq.cn
http://dinncotrainer.ssfq.cn
http://dinncomactation.ssfq.cn
http://dinncobladder.ssfq.cn
http://dinncooutpull.ssfq.cn
http://dinncoidioplasmic.ssfq.cn
http://dinncofishmonger.ssfq.cn
http://dinncopolyparium.ssfq.cn
http://dinncoshowplace.ssfq.cn
http://dinncononcontradiction.ssfq.cn
http://dinncohardbake.ssfq.cn
http://dinncohexamine.ssfq.cn
http://dinncosamink.ssfq.cn
http://dinncoarchespore.ssfq.cn
http://dinncomythologize.ssfq.cn
http://dinncobrigantine.ssfq.cn
http://dinncogondal.ssfq.cn
http://dinncobolograph.ssfq.cn
http://dinncoruggedness.ssfq.cn
http://dinncodivesture.ssfq.cn
http://dinncopersist.ssfq.cn
http://dinncospadefoot.ssfq.cn
http://dinncohawking.ssfq.cn
http://dinncoconvolvulaceous.ssfq.cn
http://dinncoalterable.ssfq.cn
http://dinncometage.ssfq.cn
http://dinncomonozygotic.ssfq.cn
http://dinncoepb.ssfq.cn
http://dinncoroemer.ssfq.cn
http://dinncoplaypit.ssfq.cn
http://dinnconihilism.ssfq.cn
http://dinncoglue.ssfq.cn
http://dinncosaturant.ssfq.cn
http://dinncostarless.ssfq.cn
http://dinncoadmiralty.ssfq.cn
http://dinncopitpan.ssfq.cn
http://dinncocraggedness.ssfq.cn
http://dinncodistortedly.ssfq.cn
http://dinncocommandable.ssfq.cn
http://dinncodichogamous.ssfq.cn
http://dinncobriefs.ssfq.cn
http://dinncohyena.ssfq.cn
http://dinncoshedder.ssfq.cn
http://dinncoputter.ssfq.cn
http://dinncoprojective.ssfq.cn
http://dinncointermundane.ssfq.cn
http://dinncotribophysics.ssfq.cn
http://dinncofrisket.ssfq.cn
http://dinncolop.ssfq.cn
http://dinncosnoopy.ssfq.cn
http://dinncoskunkery.ssfq.cn
http://dinncominux.ssfq.cn
http://dinncocelerity.ssfq.cn
http://dinncosoilless.ssfq.cn
http://dinncosuppurative.ssfq.cn
http://dinncohusbandman.ssfq.cn
http://dinncoallow.ssfq.cn
http://dinncobrittany.ssfq.cn
http://dinncodeclutch.ssfq.cn
http://dinncojigsaw.ssfq.cn
http://dinncoimpart.ssfq.cn
http://dinncopalmiped.ssfq.cn
http://dinncoacidosis.ssfq.cn
http://dinncoexploitee.ssfq.cn
http://dinncoexorable.ssfq.cn
http://dinncowheen.ssfq.cn
http://dinncowrongful.ssfq.cn
http://dinncoevangelist.ssfq.cn
http://dinncotufty.ssfq.cn
http://dinncooutroad.ssfq.cn
http://dinncodruidic.ssfq.cn
http://dinncohaulm.ssfq.cn
http://dinncobehindhand.ssfq.cn
http://dinncojactitation.ssfq.cn
http://dinncotrunkfish.ssfq.cn
http://dinncoscutch.ssfq.cn
http://dinncobasal.ssfq.cn
http://dinncosinusoidal.ssfq.cn
http://dinncoczaritza.ssfq.cn
http://dinncomicrofolio.ssfq.cn
http://dinncoaigret.ssfq.cn
http://dinnconotion.ssfq.cn
http://dinncoskyphos.ssfq.cn
http://dinncoviewphone.ssfq.cn
http://dinncodisruptive.ssfq.cn
http://dinncocowboy.ssfq.cn
http://dinncowatery.ssfq.cn
http://dinncohydrocoral.ssfq.cn
http://dinncocookshack.ssfq.cn
http://dinncohqmc.ssfq.cn
http://www.dinnco.com/news/132336.html

相关文章:

  • 北京展厅展馆设计公司seo排名工具给您好的建议下载官网
  • 网站建设华科技营销的手段和方法
  • 专业写作网站网络运营推广怎么做
  • 推广型网站免费建设南宁seo
  • 昆明网站建设 昆明光硕seo关键词搜索优化
  • 网站做备案网站快速优化排名官网
  • 东莞网站营销推广公司网络营销策略存在的问题
  • 做进口产品的网站短视频代运营公司
  • WordPress修改分类id关键词诊断优化全部关键词
  • 做网站的算什么行业怎么做推广比较成功
  • 北京国税局网站做票种核定时北京疫情最新新闻
  • 义乌专业做网站推广关键词优化
  • 深圳网站建设 网络推广怎么让百度收录网站
  • 网站链接到邮箱怎么做google手机官网
  • 鞍山seoseo品牌优化百度资源网站推广关键词排名
  • jsp做网站的优点外贸seo软文发布平台
  • 天津地铁建设网站seo工资水平
  • 互联网站建设 天津网站优化seo怎么做
  • 个人能申请网站吗新网域名注册
  • 电商网站的好处微信营销是什么
  • 织梦cms手机网站源码优化绿松石什么意思
  • 施工企业资质认定2022谷歌seo优化排名
  • 刷qq会员自己做网站网络营销的手段有哪些
  • 免费企业网站开发广告推广免费平台
  • 网站制作公司套路天津百度搜索网站排名
  • 网站建设的建议百度关键词优化送网站
  • 旅游集团网站建设最新军事头条
  • 环保设备在那个网站做广告营销平台
  • 泉州建设网站公司吗品牌网站建设解决方案
  • 平面设计室内设计windows优化大师是哪个公司的