Zlpt_Portal/src/store/cart.ts

24 lines
569 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const cartStore = defineStore('cart', {
state: () => {
return {
cartNum: 0
}
},
actions: {
SET_CART_NUM(val: number) {
this.cartNum = val
}
},
persist: {
enabled: true, // 开启数据缓存
strategies: [
{
// 自定义存储的 key默认是 store.$id
key: 'cart',
storage: localStorage, //缓存模式 可选 localStorage sessionStorage
paths: ['cartNum',]
}
]
}
})