Skip to content

Commit ba33c52

Browse files
committed
update
1 parent 35e08d9 commit ba33c52

File tree

4 files changed

+7
-54
lines changed

4 files changed

+7
-54
lines changed

src/components/common/shoplist.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default {
109109
this.offset += 20;
110110
this.showLoading = true;
111111
let res = await shopList(this.latitude, this.longitude, this.offset, this.restaurantCategoryId);
112-
this.shopListArr = this.shopListArr.concat(res);
112+
this.shopListArr = [...this.shopListArr, ...res];
113113
this.showLoading = false;
114114
//当获取数据小于20,说明没有更多数据,不需要再次请求数据
115115
if (res.length < 20) {

src/page/shop/shop.vue

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@
291291
}
292292
},
293293
created(){
294-
//获取上个页面传递过来的geohash值
295294
this.geohash = this.$route.query.geohash;
296-
//获取上个页面传递过来的shopid值
297295
this.shopId = this.$route.query.id;
298296
//初始化购物车,获取存储在localStorage中的购物车商品信息
299297
this.INIT_BUYCART();
@@ -332,11 +330,8 @@
332330
return null;
333331
}
334332
},
335-
/**
336-
* 监听cartList变化,更新当前商铺的购物车信息shopCart,同时返回一个新的对象,因为组件buyCart需要监听shopCart的变化
337-
*/
338333
shopCart: function (){
339-
return Object.assign({},this.cartList[this.shopId]);
334+
return {...this.cartList[this.shopId]};
340335
},
341336
//购物车中总共商品的数量
342337
totalNum: function (){
@@ -452,12 +447,9 @@
452447
* 初始化和shopCart变化时,重新获取购物车改变过的数据,赋值 categoryNum,totalPrice,cartFoodList,整个数据流是自上而下的形式,所有的购物车数据都交给vuex统一管理,包括购物车组件中自身的商品数量,使整个数据流更加清晰
453448
*/
454449
initCategoryNum(){
455-
//左侧食品列表当前分类中已加入购物车的商品数量
456450
let newArr = [];
457451
let cartFoodNum = 0;
458-
//购物车总共的价格
459452
this.totalPrice = 0;
460-
//购物车中所有商品的详细信息列表
461453
this.cartFoodList = [];
462454
this.menuList.forEach((item, index) => {
463455
if (this.shopCart&&this.shopCart[item.foods[0].category_id]) {
@@ -488,18 +480,15 @@
488480
}
489481
})
490482
this.totalPrice = this.totalPrice.toFixed(2);
491-
this.categoryNum = newArr.concat([]);
483+
this.categoryNum = [...newArr];
492484
},
493-
//控制显示购物车中已选商品列表
494485
toggleCartList(){
495486
this.showCartList = !this.showCartList;
496487
},
497-
//清空当前商铺的购物车信息
498488
clearCart(){
499489
this.toggleCartList();
500490
this.CLEAR_CART(this.shopId);
501491
},
502-
//监听购物车组件下落的圆点,控制购物车图标进行运动效果
503492
listenInCart(){
504493
if (!this.receiveInCart) {
505494
this.receiveInCart = true;
@@ -508,7 +497,6 @@
508497
})
509498
}
510499
},
511-
//点击评论分类,获取数据
512500
async changeTgeIndex(index, name){
513501
this.ratingTageIndex = index;
514502
this.ratingOffset = 0;
@@ -518,7 +506,6 @@
518506
this.ratingList = this.ratingList.reverse();
519507
}
520508
},
521-
//页面下拉至底部,加载更多
522509
async loaderMoreRating(){
523510
if (this.preventRepeatRequest) {
524511
return
@@ -527,7 +514,7 @@
527514
this.preventRepeatRequest = true;
528515
this.ratingOffset += 10;
529516
let ratingDate = await getRatingList(this.ratingOffset, this.ratingTagName);
530-
this.ratingList = this.ratingList.concat(ratingDate);
517+
this.ratingList = [...this.ratingList,...ratingDate];
531518
this.loadRatings = false;
532519
if (ratingDate.length >= 10) {
533520
this.preventRepeatRequest = false;
@@ -555,11 +542,9 @@
555542
})
556543
}
557544
},
558-
//监听shopCart的变化
559545
shopCart: function (value){
560546
this.initCategoryNum();
561547
},
562-
//监听购物车中商铺列表的变化,当length为0时将列表隐藏
563548
cartFoodList: function (value){
564549
if(!value.length){
565550
this.showCartList = false;

src/store/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ const state = {
3333
question: null,//问题详情
3434
//增加地址的几个key值
3535
newAddress:{},
36-
// address:null,
37-
// address_detail:null,
38-
// geohash:null,
39-
// name:null,
40-
// phone:null,
41-
// phone_bk:null,
42-
// poi:null,
43-
// poi_type:null,
4436
}
4537

4638
export default new Vuex.Store({

src/store/mutations.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ export default {
108108
cart[shopid][category_id][item_id][food_id]['sku_id'] = sku_id;
109109
cart[shopid][category_id][item_id][food_id]['stock'] = stock;
110110
}
111-
//返回一个新的对象,否则计算属性无法监听到数据的变化
112-
state.cartList = Object.assign({}, cart);
111+
state.cartList = {...cart};
113112
//存入localStorage
114113
setStore('buyCart', state.cartList);
115114
},
@@ -127,8 +126,7 @@ export default {
127126
if (cart[shopid] && cart[shopid][category_id] && cart[shopid][category_id][item_id] && cart[shopid][category_id][item_id][food_id]) {
128127
if (cart[shopid][category_id][item_id][food_id]['num'] > 0) {
129128
cart[shopid][category_id][item_id][food_id]['num']--;
130-
//返回一个新的对象,否则计算属性无法监听到数据的变化
131-
state.cartList = Object.assign({}, cart);
129+
state.cartList = {...cart};
132130
//存入localStorage
133131
setStore('buyCart', state.cartList);
134132
} else {
@@ -147,7 +145,7 @@ export default {
147145
//清空当前商品的购物车信息
148146
[CLEAR_CART](state, shopid) {
149147
state.cartList[shopid] = null;
150-
state.cartList = Object.assign({}, state.cartList);
148+
state.cartList = {...state.cartList};
151149
setStore('buyCart', state.cartList);
152150
},
153151
// 记录用户信息
@@ -264,28 +262,6 @@ export default {
264262
[SAVE_QUESTION](state, question) {
265263
state.question = {...question};
266264
},
267-
// [ADD_ADDRESS](state, {
268-
// address,
269-
// address_detail,
270-
// geohash,
271-
// name,
272-
// phone,
273-
// phone_bk,
274-
// poi,
275-
// poi_type,
276-
// }){
277-
// let addressList = state.newAddress;
278-
// addressList['address']=address;
279-
// addressList['address_detail']=address_detail;
280-
// addressList['geohash']=geohash;
281-
// addressList['name']=name;
282-
// addressList['phone']=phone;
283-
// addressList['phone_bk']=phone_bk;
284-
// addressList['poi']=poi;
285-
// addressList['poi_type']=poi_type;
286-
// state.newAddress = Object.assign({}, addressList);
287-
// state.removeAddress = state.removeAddress.unshift(state.newAddress)
288-
// }
289265
[ADD_ADDRESS](state, obj){
290266
state.newAddress = {...obj};
291267
state.removeAddress = state.removeAddress.unshift(state.newAddress)

0 commit comments

Comments
 (0)