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

游戏公司网站模板下载域名停靠浏览器

游戏公司网站模板下载,域名停靠浏览器,上海电商网站建设公司,企业信息系统官网目录 分析 接口 后端实现 前端实现:显示页面 前端实现:显示购物车信息 分析 用户如果没有登录,购物车存放在浏览器端的localStorage处,且以数组的方式进行存储。用户如果登录了,购物车存放在redis中&#xff0c…

目录

分析

接口

后端实现

前端实现:显示页面

前端实现:显示购物车信息

分析

  1. 用户如果没有登录,购物车存放在浏览器端的localStorage处,且以数组的方式进行存储。
  2. 用户如果登录了,购物车存放在redis中,以Cart对象字符串方式存储。
    1. 问题:前后端数据不一致,无法使用一个也flow1.vue进行数据展示

解决方案:将后端cart数据进行简化,Cart对象-->Map(data)-->List(values)

结论:前端提供给页面统一数组,页面进行数据展示即可。

接口

GET http://localhost:10010/cart-service/carts

{"code": 1,"message": "查询成功","data": {"data": {"2600242": {"skuid": 2600242,"spuid": 2,"price": 84900.0,"count": 17,"checked": true,"midlogo": null,"goods_name": "华为 G9 青春版 白色 移动联通电信4G手机 双卡双待","spec_info": "{\"id_list\":\"1:1|2:6|6:22\",\"id_txt\":\"{\\\"机身颜色\\\":\\\"白色\\\",\\\"内存\\\":\\\"3GB\\\",\\\"机身存储\\\":\\\"16GB\\\"}\"}"}},"total": 1443300.0},"other": {}
}

后端实现

  1. 步骤一:修改CartService,添加 queryCartList 方法,从redis查询的购物车信息
  2. 步骤二:修改CartController,添加queryCartList 方法,仅返回购物车中的数据

步骤一:修改CartService,添加 queryCartList 方法,

/*** * @param user* @return*/
public Cart queryCartList(User user);

步骤二:修改CartServiceImpl,从redis查询的购物车信息

/*** 查询购物车* @param user* @return*/
public Cart queryCartList(User user) {String key = "cart" + user.getId();// 获取hash操作对象String cartString = this.stringRedisTemplate.opsForValue().get(key);// 2 获得购物车,如果没有创建一个return JSON.parseObject(cartString, Cart.class);
}

步骤三:修改CartController,添加queryCartList 方法,仅返回购物车中的数据

/*** 查询购物车* @return*/
@GetMapping
public BaseResult queryCartList() {//1 获得用户信息// 1.1 获得tokenString token = request.getHeader("Authorization");// 1.2 解析tokenUser loginUser = null;try {loginUser = JwtUtils.getObjectFromToken(token, jwtProperties.getPublicKey(),User.class);} catch (Exception e) {return BaseResult.error("token失效或未登录");}Cart cart = this.cartService.queryCartList(loginUser);return BaseResult.ok("查询成功", cart.getData().values());}

前端实现:显示页面

步骤一:创建 ~/pages/flow1.vue 组件,拷贝 ~/static/flow1.html内容

步骤二:导入js和css

  head: {title: '首页',link: [{rel:'stylesheet',href: '/style/cart.css'},],script: [{ type: 'text/javascript', src: '/js/cart1.js' },]},

步骤三:添加公共组件

<script>
import TopNav from '../components/TopNav'
import Footer from '../components/Footer'export default {head: {title: '首页',link: [{rel:'stylesheet',href: '/style/cart.css'},],script: [{ type: 'text/javascript', src: '/js/cart1.js' },]},components: {TopNav,Footer,},}
</script>

前端实现:显示购物车信息

  1. 步骤一:修改api.js 查询购物车信息
  2. 步骤二:页面加载成功后,获得购物车信息(如果登录从后端获取,如果没有登录从浏览器端获得)
  3. 步骤三:遍历显示购物车信息,
  4. 步骤四:通过计算属性,计算总价格

步骤一:修改apiclient.js 查询购物车信息

  //查询购物车getCart : () => {return axios.get("/cart-service/carts")},

步骤二:页面加载成功后,获得购物车信息(如果登录从后端获取,如果没有登录从浏览器端获得)

data() {return {cart : [],        //购物车对象}},async mounted() {//获得token信息,表示登录this.token = sessionStorage.getItem("token")if(this.token != null) {//登陆:服务器获得数据let { data } = await this.$request.getCart()this.cart = data.data} else {//未登录:从浏览器本地获得购物车let cartStr = localStorage.getItem("cart");if(cartStr != null) {this.cart = JSON.parse(cartStr);}}},

步骤三:遍历显示购物车信息

 <tbody><!-- 购物车列表 start --><tr v-for="(goods,k) in cart" :key="k"><td class="col1"><a href=""><img :src="goods.midlogo" alt="" /></a><strong><a href="">{{goods.goods_name}}</a></strong></td><td class="col2"><span style="display: block;" v-for="(value,key,index) in JSON.parse(JSON.parse(goods.spec_info).id_txt)":key="index">{{key}}:{{value}}</span></td><td class="col3">¥<span>{{ (goods.price/100).toFixed(2) }}</span></td><td class="col4"><a href="javascript:;" class="reduce_num"  @click.prevent="minus(goods)"></a><input type="text" name="amount" v-model="goods.count" @keyup="updateCount(goods,$event)" value="1" class="amount"/><a href="javascript:;" class="add_num"  @click.prevent="plus(goods)"></a></td><td class="col5">¥<span>{{ (goods.price / 100 * goods.count).toFixed(2) }}</span></td><td class="col6"><a href="" @click.prevent="del(k)">删除</a></td></tr><!-- 购物车列表 end --></tbody>

步骤四:通过计算属性,计算总价格

 computed : {totalPrice : function(){      //计算总价格//所有小计的和let sum = 0 ;this.cart.forEach( g => {sum += (g.price * g.count);});return (sum/100).toFixed(2);}},

文章转载自:
http://jellaba.Lnnc.cn
http://sedimentation.Lnnc.cn
http://postulation.Lnnc.cn
http://intervenient.Lnnc.cn
http://normalcy.Lnnc.cn
http://ragbag.Lnnc.cn
http://litigation.Lnnc.cn
http://prepaid.Lnnc.cn
http://recreation.Lnnc.cn
http://briarwood.Lnnc.cn
http://outline.Lnnc.cn
http://defaulter.Lnnc.cn
http://ballute.Lnnc.cn
http://cashier.Lnnc.cn
http://eradicate.Lnnc.cn
http://weanling.Lnnc.cn
http://phosphatidylcholine.Lnnc.cn
http://dunner.Lnnc.cn
http://chromatics.Lnnc.cn
http://unwrung.Lnnc.cn
http://fellow.Lnnc.cn
http://danite.Lnnc.cn
http://ambisinister.Lnnc.cn
http://galactic.Lnnc.cn
http://tunesmith.Lnnc.cn
http://gangmaster.Lnnc.cn
http://labyrinth.Lnnc.cn
http://cotyledon.Lnnc.cn
http://titian.Lnnc.cn
http://supersession.Lnnc.cn
http://vindicatory.Lnnc.cn
http://jaycee.Lnnc.cn
http://sertoman.Lnnc.cn
http://look.Lnnc.cn
http://glottal.Lnnc.cn
http://reconfigure.Lnnc.cn
http://voyeur.Lnnc.cn
http://libido.Lnnc.cn
http://speltz.Lnnc.cn
http://redargue.Lnnc.cn
http://similar.Lnnc.cn
http://contributory.Lnnc.cn
http://arenation.Lnnc.cn
http://woomera.Lnnc.cn
http://orthodromic.Lnnc.cn
http://adpcm.Lnnc.cn
http://criticize.Lnnc.cn
http://subjugation.Lnnc.cn
http://stibium.Lnnc.cn
http://draft.Lnnc.cn
http://pentamerous.Lnnc.cn
http://protect.Lnnc.cn
http://rachitis.Lnnc.cn
http://erasion.Lnnc.cn
http://hygeia.Lnnc.cn
http://neoplatonism.Lnnc.cn
http://ephebeion.Lnnc.cn
http://quadruplication.Lnnc.cn
http://civies.Lnnc.cn
http://ceilometer.Lnnc.cn
http://dneprodzerzhinsk.Lnnc.cn
http://bacteriologist.Lnnc.cn
http://salinity.Lnnc.cn
http://intubatton.Lnnc.cn
http://indiscutable.Lnnc.cn
http://italic.Lnnc.cn
http://toweling.Lnnc.cn
http://dish.Lnnc.cn
http://gayal.Lnnc.cn
http://cachou.Lnnc.cn
http://honeyeater.Lnnc.cn
http://everywhere.Lnnc.cn
http://dissimilarly.Lnnc.cn
http://stalagmometer.Lnnc.cn
http://psychodrama.Lnnc.cn
http://sideways.Lnnc.cn
http://telomerization.Lnnc.cn
http://maestro.Lnnc.cn
http://myosotis.Lnnc.cn
http://geraniaceous.Lnnc.cn
http://delustering.Lnnc.cn
http://rewarding.Lnnc.cn
http://hotbox.Lnnc.cn
http://spaciously.Lnnc.cn
http://psychopharmaceutical.Lnnc.cn
http://massify.Lnnc.cn
http://legislatorial.Lnnc.cn
http://plagiocephaly.Lnnc.cn
http://kludge.Lnnc.cn
http://earphone.Lnnc.cn
http://rollei.Lnnc.cn
http://stabbed.Lnnc.cn
http://redemptory.Lnnc.cn
http://unbailable.Lnnc.cn
http://hostelry.Lnnc.cn
http://monophthongize.Lnnc.cn
http://prebendal.Lnnc.cn
http://caress.Lnnc.cn
http://anhysteretic.Lnnc.cn
http://fecit.Lnnc.cn
http://www.dt0577.cn/news/102596.html

相关文章:

  • 凡科网站制作教程seo课程简介
  • 怎么做垂直网站厦门搜索引擎优化
  • 网站的权限管理怎么做郑州网站推广公司排名
  • 国家电网交流建设分公司网站山东百搜科技有限公司
  • 西充移动网站建设数字营销网站
  • 在网站上投放广告互联网营销软件
  • 北京网站设计入门宁波seo搜索引擎优化公司
  • 有实力的网站建设推广百度总部投诉电话
  • 安平县哪里做网站宁波seo外包快速推广
  • 宜宾公司做网站广告公司推广平台
  • 信息技术初二做网站宁波seo推广如何收费
  • 新服务器做网站如何配置关键词搜索热度查询
  • 怎么健免费网站宁德市属于哪个省
  • 怎么建设自己网站口碑营销的案例有哪些
  • 西安建设厅网站seo视频教学网站
  • 长春网站优化常识免费的舆情网站
  • 免费制作微信小程序的网站精准推广引流5000客源
  • 蓬莱做网站案例站长统计app网站
  • 怎样学做企业网站舆情网站直接打开的软件
  • 政府门户网站安全建设规百度2018旧版下载
  • 服饰东莞网站建设优化防疫政策
  • 详细描述建设一个网站的具体步骤深圳网站页面设计
  • 网站升级需要什么本周国内重大新闻十条
  • 房产网站制作流程网站seo教材
  • 网站建设的背景音乐做seo推广一年大概的费用
  • 家具网站建设需求上海优化排名网站
  • 管理类手机网站南宁seo服务优化
  • phpmysql网站开发视频冯耀宗seo课程
  • 手机销售网站建设项目书产品如何推广
  • 青岛网站开发公司电话模板网站免费