choosed.js 855 B

1234567891011121314151617181920212223
  1. export default {
  2. namespaced: true,
  3. state: {
  4. list: []
  5. },
  6. getters: {
  7. S: state => state.list.reduce((t, e) => t + (e.size.S || 0), 0),
  8. M: state => state.list.reduce((t, e) => t + (e.size.M || 0), 0),
  9. L: state => state.list.reduce((t, e) => t + (e.size.L || 0), 0),
  10. XL: state => state.list.reduce((t, e) => t + (e.size.XL || 0), 0),
  11. XXL: state => state.list.reduce((t, e) => t + (e.size.XXL || 0), 0),
  12. XXXL: state => state.list.reduce((t, e) => t + (e.size.XXXL || 0), 0),
  13. total: state => state.list.reduce((t, e) => Object.keys(e.size).reduce((tt, ee) => tt + (e.size[ee] || 0), t), 0)
  14. },
  15. mutations: {
  16. CHOOSE(state, payload) { // 用户点击确定后将尺寸选择中的 choosed 放入 state 中
  17. state.list = payload
  18. },
  19. CLEAR(state) { // 退出页面/立即购买/加入购物车后清空 choosed
  20. state.list = []
  21. }
  22. }
  23. }