使用vue来实现当当网

2025-12-13 0 104

<div id=\”main\”>
<div><img src=\”images/shopping_myshopping.gif\” alt=\”shopping\”> <a href=\”#\”>全场免运费活动中</a></div>
<!–为您推荐商品开始–>
<div class=\”shopping_commend\”>
<div class=\”shopping_commend_left\”>根据您挑选的商品,当当为您推荐</div>
<div class=\”shopping_commend_right\”><img src=\”images/shopping_arrow_up.gif\” alt=\”shopping\”
@click=\”show\”></div>
</div>
<div id=\”shopping_commend_sort\” v-show=\”bool\”>
<ul v-for=\”(item,index) in list\” :key=\”index\”>
<li class=\”shopping_commend_list_1\”>{{item.title}}<a href=\”#\” class=\”blue\”></a></li>
<li class=\”shopping_commend_list_2\”>¥{{item.price}}</li>
<li class=\”shopping_commend_list_3\”>¥{{item.discount}}</li>
<li class=\”shopping_commend_list_4\”>
<a href=\”#\” class=\”shopping_yellow\” @click=\”add(item)\”>购买</a>
</li>
</ul>
</div>
<div class=\”shopping_list_top\”>您已选购以下商品</div>
<div class=\”shopping_list_border\”>
<table width=\”100%\” border=\”0\” cellspacing=\”0\” cellpadding=\”0\”>
<tr class=\”shopping_list_title\”>
<td>商品名</td>
<td>单品积分</td>
<td>市场价</td>
<td>当当价</td>
<td>数量</td>
<td>删除</td>
</tr>
</table>
<table width=\”100%\” border=\”0\” cellspacing=\”0\” cellpadding=\”0\”>
<tr class=\”shopping_product_list\” v-for=\”(item,index) in box\” :key=\”index\”>
<td class=\”shopping_product_list_1\”><a href=\”#\” class=\”blue\”>{{item.title}}</a></td>
<td class=\”shopping_product_list_2\”>{{item.product}}</td>
<td class=\”shopping_product_list_3\”>¥<span>{{item.price}}</span></td>
<td class=\”shopping_product_list_4\”>¥<span>{{item.discount}}</span> </td>
<td class=\”shopping_product_list_5\”>
<input type=\”button\” value=\”-\” @click=\”reduces(item)\” /> <!–减–>
<input type=\”text\” v-model=\”item.val\”>
<input type=\”button\” value=\”+\” @click=\”item.val++\” />
</td>
<td class=\”shopping_product_list_6\”><a href=\”javascript:void(0)\” class=\”blue\”
@click=\”dele(index)\”>删除</a></td>
</tr>
</table>
<div class=\”shopping_list_end\” >
<ul>
<li class=\”shopping_list_end_1\”@click=\”clears\”><input type=\”image\” src=\”images/shopping_balance.gif\”></li>
<li class=\”shopping_list_end_2\”>¥<span id=\”sumPrice\”>{{total}}</span></li>
<li class=\”shopping_list_end_3\”>商品金额总计:</li>
<li class=\”shopping_list_end_4\”>您共节省:<label class=\”shopping_list_end_yellow\”>¥<span
id=\”sumDis\”>{{saves}}</span></label><br />
可获商品积分:<label class=\”shopping_list_end_yellow\” id=\”sumScore\”>{{intes}}</label>
</li>
</ul>
</div>
</div>

</div>

new Vue({
el: \”#main\”,//节点,element简写,选择器
data: {//vue存放数据的地方,是以键值对的方式来存放
bool:true,//做标识
list: [{
title: \’JavaScript DOM编程艺术\’,
price: \’39.00\’,
discount: \’29.30\’
},
{
title: \’解禁(当当网独家首发)\’,
price: \’28.00\’,
discount: \’19.40\’
},
{
title: \’地王之王(金融危机下房地产行…)\’,
price: \’32.80\’,
discount: \’25.10\’
},
{
title: \’逃庄\’,
price: \’36.00\’,
discount: \’27.70\’
},
{
title: \’深入浅出MySQL数据库开发,优…\’,
price: \’59.00\’,
discount: \’47.20\’
},
{
title: \’大玩家(马未都、王刚推荐!)\’,
price: \’34.80\’,
discount: \’20.60\’
},
{
title: \’都市风水师–官场风水小说\’,
price: \’39.80\’,
discount: \’30.50\’
},
{
title: \’国戏(以麻将术解读宦海沉浮…)\’,//书名
price: \’25.00\’,//原价
discount: \’17.30\’//打折后
},
],
box:[
{
title:\’私募(首部披露资本博弈秘密的金融…\’,
product:189,
price:\’25.00\’,
val:1,
discount:\’18.90\’,
},
{
title:\’小团圆(张爱玲最神秘小说遗稿)\’,
product:173,
price:\’17.30\’,
val:1,
discount:\’10.90\’,
},
{
title:\’不抱怨的世界(畅销全球80国的世界…\’,
product:154,
price:\’24.80\’,
val:1,
discount:\’15.40\’,
},
{
title:\’福玛特双桶洗衣机XPB20-07S\’,
product:358,
price:\’458.00\’,
val:1,
discount:\’358.00\’,
},
{
title:\’PHP和MySQL Web开发 (原书第4版)\’,
product:712,
price:\’95.00\’,
val:1,
discount:\’71.20\’,
},
{
title:\’法布尔昆虫记(再买¥68.3即可参加“满199元减10元现金”活)\’,//书名
product:10,//积分
price:\’198.00\’,//原价
val:1,
discount:\’130.70\’,//打折后
}
],
},
methods:{//vue实例存放事件的地方
//收缩
show(){
this.bool=!this.bool
},
//添加
add(item){
for (let i of this.box) {//i是对象
// console.log(i.title);
if(i.title==item.title){//判断
i.val++//数量加加
return
}
}
this.box.push({//在数组末尾添加
title:item.title,//书名
product:item.discount*10,//积分 打折后*10
price:item.price,//原价
discount:item.discount,//打折后
val:1
})
},
//添加(方法二)
// add(title,price,discount){
// let color=true;//做标识
// for (let i in this.box) {//循环数组根据下标
// if(this.box[i].title===title){//判断根据数组的下标下的书名全等于书名
// this.box[i].val++;//数组的下标数量++
// color=false;
// break
// }
// // console.log(title);
// }
// if(color){//为true时
// this.box.push({//在数组末尾添加
// title:title,//第二组中的书名数据等于第一组中的书名数据
// product:discount*10,//积分 打折后*10
// price:price,//第二组中原价数据等于第一组中的原价数据
// discount:discount,//第二组中打折后数据等于第一组中的打折后的数据
// val:1
// })
// }
// },
//点击按钮– ++
reduces(item){
if(item.val>1){//判断,数量大于1时
Vue.set(item,\’val\’,–item.val)//参数1操作的对象,叁数二添加的属性,参数3需要添加的val值
}else{
alert(\”不能再–啦\”)
item.val=1
}
},
//删除行
dele(index){
if(confirm(\”确定要删除吗?\”)){
this.box.splice(index,1)
}
},
//清空
clears(){
if(this.box.length>0){//判断当前数组长度大于0
if(confirm(\”确定要全部清空吗?\”)){
this.box = [];
}
}
}
},
computed:{
//总金额(方法一)
total(){
let boxs=0
for (let i of this.box) {
boxs+=i.discount*i.val
}
return boxs.toFixed(2)
},
// 方法二
// total(){
// let amounts=0//用于累加
// for (let i in this.box) {
// // console.log(this.box[i]);
// amounts+=this.box[i].discount*this.box[i].val
// //折扣价*数量
// // // amounts+=this.box[i].discount*this.box[i].val//打折后*数量
// }
// return amounts.toFixed(2)//保留小数位数2位
// },

//节省(方法一)
// saves(){
// let costs=0
// for (let i of this.box) {
// costs+=(i.price-i.discount)*i.val
// }
// return costs
// },
// (方法二)
saves(){
let costs=0//原价
// let beats=0//打折
for (let i in this.box) {
costs+=(this.box[i].price-this.box[i].discount)*this.box[i].val
// costs+=this.box[i].price*this.box[i].val//原价*数量
// costs+=this.box[i].price*this.box[i].val//原价*数量
// beats+=this.box[i].discount*this.box[i].val//打折*数量
// bb+=(this.box[i].discount-this.box[i].price)*this.box[i].val
}
return costs.toFixed(2)
// return (costs-beats).toFixed(2)
},

//商品积分(方法一)
intes(){
let integral=0
for (let i of this.box) {
// console.log(i.price);
integral+=i.price*i.val
}
return integral
},
// 方法二
// intes(){
// let integral=0//积分
// for (let i in this.box) {
// integral+=this.box[i].product*this.box[i].val//积分*数量
// }
// return integral
// }



saves(){
let spares=0
for (let i in this.box) {
spares+=(this.box[i].price-this.box[i].discount)*this.box[i].val//原价-打折后*数量
// console.log(this.box[i].price,this.box[i].discount,this.box[i].val);
}
return spares.toFixed(2)//保留小数位数2位
}

},

watch:{
box:{//监听的对象
deep:true,//开启深度监听
handler(news,olds){
// console.log(news)
for (let i of news) {
if(isNaN(i.val)||i.val<1){//条件判断
alert(\”非数\”)
i.val=1
}
}
}
}
},
})

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 编程相关 使用vue来实现当当网 https://www.zuozi.net/36188.html

TypeScript
下一篇: TypeScript
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务