购物车

作者: hujinjin | 来源:发表于2017-05-24 14:37 被阅读0次

产品编号产品名字购买数量产品单价产品总价操作

{{item.id}}{{item.name}}-+{{item.price | filtermoney}}{{item.price*item.quantity | filtermoney}}移除

总购买价{{animatenum | filtermoney}}总购买数量清空购物车

您的购物车为空

var vm = new Vue({

el: "#app",

data: {

totalPrice: 0,

animatenum: 0,

message: [{

id: 007,

name: 'iphone5s',

quantity: 3,

price: 4000

}, {

id: 1340,

name: 'iphone5',

quantity: 9,

price: 3000

}, {

id: 7758,

name: 'imac',

quantity: 4,

price: 7000

}, {

id: 2017,

name: 'ipad',

quantity: 5,

price: 6000

}]

},

watch: {

toComput2: function(newValue, oldValue) {

this.tween(newValue, oldValue);

}

},

computed: {

//计算总金额

toComput2: function() {

var vm = this;

//每次进来要重置总金额

vm.totalPrice = 0;

this.message.forEach(function(mess) {

vm.totalPrice += parseInt(mess.price * mess.quantity);

})

return this.totalPrice;

}

},

filters: {

filtermoney: function(value) {

return '¥' + value;

}

},

mounted: function() {

this.tween('97000', '0');

},

methods: {

//计算总数的方法为什么写在methods里面就不行?

toComput: function() {

var vm = this;

vm.message.forEach(function(mess) {

vm.totalPrice += parseInt(mess.price * mess.quantity);

})

return vm.totalPrice;

},

add: function(index) {

var vm = this;

vm.message[index].quantity++;

},

subtract: function(index) {

var vm = this;

vm.message[index].quantity--;

if(vm.message[index].quantity <= 0) {

if(confirm("你确定移除该商品?")) {

vm.message.splice(index, 1)

}

}

},

remove: function(index) {

var vm = this;

if(confirm("你确定移除该商品?")) {

vm.message.splice(index, 1)

}

},

empty: function() {

var vm = this;

vm.message.splice(0, vm.message.length);

},

jia: function(index) {

var vm = this;

vm.arr[index].one++;

},

tween: function(newValue, oldValue) {

var vm = this;

var twen = new TWEEN.Tween({

animatenum: oldValue

});

function animate() {

requestAnimationFrame(animate);

TWEEN.update();

};

twen.to({

animatenum: newValue

}, 750);

twen.onUpdate(function() {

//toFixed();保留几位小数

vm.animatenum = this.animatenum.toFixed();

})

twen.start();

animate();

}

}

});

相关文章

  • 商城之购物车

    购物车管理: 包含功能:提交商品到购物车、显示购物车列表、删除购物车里商品、修改购物车、清空购物车等等 1、购...

  • 购物车模块实现

    1、购物车列表功能实现 点击加入购物车或者点击购物车图标后进入购物车页面,在购物车页面中首先渲染cartList的...

  • SSM框架学习日记(6)——购物车模块

    购物车相关接口 添加购物车,购物车列表,更新商品数量,删除购物车先新建CartController和CartSer...

  • 8.5-高并发下的互联网电商购物车实战-加入购物车接口开发—小滴

    高并发下的互联网电商购物车实战-加入购物车接口开发 简介:电商购物车实现案例-加入购物车接口开发 添加购物车接口 ...

  • day11购物车10-细节完善

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11购物车08-代理的简单实现

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11-购物车06-清空和购买

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11购物车07-KVO的应用

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11购物车09-代理设计模式

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • 8.购物车管理

    购物车管理模块是属于用户侧模块,主要有7个接口:添加商品到购物车、更新购物车商品数、移除购物车商品、查看购物车当中...

网友评论

      本文标题:购物车

      本文链接:https://www.haomeiwen.com/subject/fqxgxxtx.html