python购物车结算_python代码实现购物车(django的redis与vue)

本文展示了如何使用Python Django框架、Redis存储购物车数据,并结合Vue.js进行前端交互,实现购物车的商品增减、总价计算以及商品删除功能。在页面加载时从服务器获取购物车信息,通过Vue方法处理加减操作并实时更新总价,同时提供支付接口与商品删除接口。
摘要由CSDN通过智能技术生成
全部商品 2
  • 商品名称
  • 商品价格
  • 数量
  • 小计
  • 操作
  • {{i.name}}
  • {{i.price}}元
  • +

    -

  • {{i.count*i.price}}元
  • 删除
  • 合计(不含运费):¥{{totalPrice}}
    共计2件商品
  • 去结算

name:'cart',

data() {return{

goods:[],

src:'/hou/static/goods/',

totalPrice:0

}

},//页面加载之前获取购物车参数信息

mounted(){//方法共用

this.get_data()

},

methods:{//添加点击事件 加一

add:function(index){

this.goods[index].count++;

this.totalPricefn(index,'+');

},//添加点击事件 减一

minus:function(index){if(this.goods[index].count>1){

this.goods[index].count--;

this.totalPricefn(index,'-');

}

},//计算总价

totalPricefn:function(index,params){if(params=='+'){

this.totalPrice+= this.goods[index].price*1;

}else if(params =='-'){

this.totalPrice-= this.goods[index].price*1;

}else{

this.totalPrice+= this.goods[index].price*this.goods[index].count;

}

},//支付

pay:function(){

let data={"total":this.totalPrice,

}

this.axios({

url:'/api/pay/pay/',

method:'get',

params:data

}).then(res=>{//let url=res.data.url;

location.href=url;

})

},//删除商品

delx:function(id){

let data={'uid':localStorage.getItem('uid'),'gid':id

}

this.axios({

url:'/api/goods/cart/',

method:'delete',

data:data

}).then(res=>{

this.get_data();

})

},//获取初始信息

get_data:function(){

this.axios({

url:'/api/goods/cart/',

method:'get',

params:{"id":localStorage.getItem('uid')}

}).then(res=>{

this.goods=res.data.data;

this.totalPrice=0;

this.goods.forEach((item,index)=>{

this.totalPricefn(index,'');

})

})

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值