优化
This commit is contained in:
@@ -4,7 +4,7 @@ import { getCompanyId } from '@/utils';
|
||||
|
||||
const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
state: (): { shoppingCartList: GoodsBean[] } => ({
|
||||
shoppingCartList: uni.getStorageSync(`shoppingCart_${getCompanyId()}`) as GoodsBean[]
|
||||
shoppingCartList: uni.getStorageSync(`shoppingCart_${getCompanyId()}`) == '' ? [] : uni.getStorageSync(`shoppingCart_${getCompanyId()}`) as GoodsBean[]
|
||||
}),
|
||||
|
||||
persist: {
|
||||
@@ -16,7 +16,7 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
uni.setStorageSync(`shoppingCart_${getCompanyId()}`, JSON.parse(value).shoppingCartList);
|
||||
},
|
||||
getItem(key) {
|
||||
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)); // [!code warning]
|
||||
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)) || []; // [!code warning]
|
||||
}
|
||||
},
|
||||
// 部分持久化状态的点符号路径数组,[]意味着没有状态被持久化(默认为undefined,持久化整个状态)
|
||||
@@ -33,7 +33,7 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
},
|
||||
|
||||
getSameGoodsIndex: (state) => (goodsId: string, colorId: string, sizeId: string) => {
|
||||
return state.shoppingCartList.findIndex(res => res.id === goodsId && res.checkedStock.colorId === colorId && res.checkedStock.sizeId === sizeId);
|
||||
return state.shoppingCartList.findIndex(res => res.id === goodsId && res.checkedStock.colorId === colorId && res.checkedStock.sizeId === sizeId) || -1;
|
||||
}
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user