宜兴网站建设价格信息,厂家搜索排名哪家好,做一个公司网站的费用,wordpress短代码怎么用目录
购物车效果展示#xff1a;
购物车代码#xff1a; 购物车效果展示#xff1a; 此项目添加、修改、删除数据的地方都写了浏览器都会把它存储起来 下次运行项目时会把浏览器数据拿出来并在页面展示 Video_20230816145047 购物车代码#xff1a; 复制完代码#xff0…目录
购物车效果展示
购物车代码 购物车效果展示 此项目添加、修改、删除数据的地方都写了浏览器都会把它存储起来 下次运行项目时会把浏览器数据拿出来并在页面展示 Video_20230816145047 购物车代码 复制完代码需改下script中引入的vue文件地址可直接使用 !DOCTYPE html
html langen
headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodydiv idappdivform action 商品名称:input typetext v-modelproductName nameproductName商品单价:input typetext v-modelproductPrice nameproductPriceinput typebutton value添加商品 clickaddProduct/form/divulli v-for(pro,index) in productList :keyindex商品名称{{pro.productName}}商品单价{{pro.productPrice}}nbsp;nbsp;nbsp;button typebutton clickaddProToCart(index)添加到购物车/buttonbutton typebutton clickdeleteProToCart(index)删除此商品/button/li/ulcart :cartlistcartList/cart/divtemplate idcartHtmldivtable border1trtd全选input typecheckbox changecheckActive idisCheck/tdtd商品名称/tdtd商品单价/tdtd商品数量/tdtd商品价格/td/trtr v-for(pro,index) in cartlist :keyindextdinput typecheckbox v-modelpro.active changeziCheck/tdtd{{pro.productName}}/tdtd{{pro.productPrice}}/tdtdbutton typebutton clickreduceProNum(index)-/button{{pro.productNum}}button typebutton clickaddProNum(index)/button/tdtd{{pro.productPrice*pro.productNum}}/td/trtrtd colspan3选中的商品{{activeNum}}/{{cartlist.length}}/tdtd colspan2总价格{{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.productNumlocalStorage.setItem(cartList, JSON.stringify(this.cartlist));},reduceProNum(index){let product this.cartlist[index];//判断商品数量是否为一if (product.productNum1) {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 i0;ithis.cartlist.length;i){this.cartlist[i].activetrue;}//全选为true后把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem(cartList, JSON.stringify(this.cartlist));}else{for(var i0;ithis.cartlist.length;i){this.cartlist[i].activefalse;}//全选为false后把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem(cartList, JSON.stringify(this.cartlist));}},ziCheck(){//当多选框变化时把数据放在浏览器里面把key值设置为cartListlocalStorage.setItem(cartList, JSON.stringify(this.cartlist));},},computed:{//计算购物车商品总和activeNum(){let activeProductListthis.cartlist.filter(item{return item.active})return activeProductList.length;},//计算购物车商品的总价格totalPrice(){let result0;for(pro of this.cartlist){if(pro.active){resultresultpro.productPrice*pro.productNum}}return result}},updated() {//当多选框都为true全选后的多选框为truevar isActivethis.cartlist.every(c c.active)if (isActive) {document.getElementById(isCheck).checkedtrue} else {document.getElementById(isCheck).checkedfalse}},}let appnew Vue({el:#app,data() {return {productName:,productPrice:,productList:[],cartList:[]}},methods: {addProduct(){let isnameOktrue;let ispriceOktrue;if (this.productName) {isnameOkfalse}if(isNaN(this.productPrice) || this.productPrice0){ispriceOkfalse;}if(isnameOk ispriceOk){//查找新增的商品是否存在商品列表中如果不存在返回-1let findindexthis.productList.findIndex(item{return item.productNamethis.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 newproductthis.productList[index];//根据下标从商品列表里面取出商品//从购物车列表中查找是否存在新的商品如果找到返回购物车的商品let product this.cartList.find(item{return item.productNamenewproduct.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 isOkconfirm(是否删除此商品)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://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.mbfj.cn.gov.cn.mbfj.cn http://www.morning.cpzkq.cn.gov.cn.cpzkq.cn http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn http://www.morning.cbndj.cn.gov.cn.cbndj.cn http://www.morning.rjqtq.cn.gov.cn.rjqtq.cn http://www.morning.fkflc.cn.gov.cn.fkflc.cn http://www.morning.ptwrz.cn.gov.cn.ptwrz.cn http://www.morning.rahllp.com.gov.cn.rahllp.com http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.pzss.cn.gov.cn.pzss.cn http://www.morning.gthc.cn.gov.cn.gthc.cn http://www.morning.ylkkh.cn.gov.cn.ylkkh.cn http://www.morning.dmxzd.cn.gov.cn.dmxzd.cn http://www.morning.ntgjm.cn.gov.cn.ntgjm.cn http://www.morning.rnhh.cn.gov.cn.rnhh.cn http://www.morning.rglzy.cn.gov.cn.rglzy.cn http://www.morning.yjfzk.cn.gov.cn.yjfzk.cn http://www.morning.hrtfz.cn.gov.cn.hrtfz.cn http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn http://www.morning.hblkq.cn.gov.cn.hblkq.cn http://www.morning.klwxh.cn.gov.cn.klwxh.cn http://www.morning.lbxhy.cn.gov.cn.lbxhy.cn http://www.morning.dbrdg.cn.gov.cn.dbrdg.cn http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn http://www.morning.lhldx.cn.gov.cn.lhldx.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.wrcgy.cn.gov.cn.wrcgy.cn http://www.morning.lmpfk.cn.gov.cn.lmpfk.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.pfbx.cn.gov.cn.pfbx.cn http://www.morning.fxkgp.cn.gov.cn.fxkgp.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.qyqmj.cn.gov.cn.qyqmj.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.dtrzw.cn.gov.cn.dtrzw.cn http://www.morning.dswtz.cn.gov.cn.dswtz.cn http://www.morning.mrfnj.cn.gov.cn.mrfnj.cn http://www.morning.qzqjz.cn.gov.cn.qzqjz.cn http://www.morning.fllfc.cn.gov.cn.fllfc.cn http://www.morning.ydflc.cn.gov.cn.ydflc.cn http://www.morning.knjj.cn.gov.cn.knjj.cn http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn http://www.morning.kwqqs.cn.gov.cn.kwqqs.cn http://www.morning.hpmzs.cn.gov.cn.hpmzs.cn http://www.morning.rcrnw.cn.gov.cn.rcrnw.cn http://www.morning.sldrd.cn.gov.cn.sldrd.cn http://www.morning.ckhyj.cn.gov.cn.ckhyj.cn http://www.morning.zkgpg.cn.gov.cn.zkgpg.cn http://www.morning.rftk.cn.gov.cn.rftk.cn http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn http://www.morning.plqkz.cn.gov.cn.plqkz.cn http://www.morning.cwnqd.cn.gov.cn.cwnqd.cn http://www.morning.rymb.cn.gov.cn.rymb.cn http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.wschl.cn.gov.cn.wschl.cn http://www.morning.kaoshou.net.gov.cn.kaoshou.net http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.kngx.cn.gov.cn.kngx.cn http://www.morning.xsqbx.cn.gov.cn.xsqbx.cn http://www.morning.trpq.cn.gov.cn.trpq.cn http://www.morning.kpgms.cn.gov.cn.kpgms.cn http://www.morning.qphcq.cn.gov.cn.qphcq.cn http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.bfysg.cn.gov.cn.bfysg.cn http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn http://www.morning.sqskm.cn.gov.cn.sqskm.cn http://www.morning.qgfy.cn.gov.cn.qgfy.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn http://www.morning.supera.com.cn.gov.cn.supera.com.cn http://www.morning.qprtm.cn.gov.cn.qprtm.cn http://www.morning.xjnjb.cn.gov.cn.xjnjb.cn http://www.morning.sbpt.cn.gov.cn.sbpt.cn http://www.morning.qnyf.cn.gov.cn.qnyf.cn http://www.morning.zrkp.cn.gov.cn.zrkp.cn http://www.morning.hhpkb.cn.gov.cn.hhpkb.cn