Vue 登录Id的传值+ 购物车的结算

一、登录Id的传值

 

    1、传值

if (res.data.code !="") {
  this.$message({
    message: "登陆成功",
    type: "success",
  });
  //传值
  sessionStorage.setItem('userid',res.data.AId)
  this.$router.push('/');
} else {
  this.$message.error("登录失败");
}

    2、接收   if 判断是为了确定你现在是否处于登录状态,

//接收
let userid = sessionStorage.getItem("userid");
if (userid != null) {
  this.jia.AAId = userid;
  this.jia.IId = id;

二、购物车的结算

    1、获取选中的Id  xuan是定义的数组   this.xuan=[] 写在这里是为了清空,防止总数叠加

//选择
handleSelectionChange(val) {
  this.xuan=[];
  this.multipleSelection = val;
  for(let index=0;index<val.length;index++)
  {
    this.xuan.push(val[index]);
  }
},

    2、 循环得到总价

 //计算
 computed:{
   //总价
   moneys(){
     var zhongjia=0;
     for(var i=0; i<this.xuan.length;i++)
     {
        zhongjia+=this.xuan[i].Price*this.xuan[i].Number;
     }
     return zhongjia
   }
 }

    3、显示

合计:<span>{{moneys}}</span>

 

      ......待续

 

posted @ 2021-10-27 21:46  魔术人生  阅读(233)  评论(0编辑  收藏  举报
复制代码