addresses.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. export default{
  2. //开启命名空间
  3. namespaced:true,
  4. //数据
  5. state:()=>({
  6. // address:JSON.parse(uni.getStorageSync('address')||'{addresses:[]}').addresses,
  7. address:[]
  8. }),
  9. //方法
  10. mutations:{
  11. //更新收货地址
  12. addAddress(state,address){
  13. state.address.push(address)
  14. },
  15. //持久化储存address
  16. saveAddressToStorage(state){
  17. uni.setStorageSync('address',JSON.stringify({addresses:state.address}))
  18. }
  19. },
  20. getters:{
  21. //收货地址
  22. addstr(state){
  23. if(!state.address.provinceName) return ''
  24. return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
  25. },
  26. getAddressList(state){
  27. let ret=[]
  28. console.log(state.address,"空吗")
  29. for (let i=0;i<state.address.length;i++){
  30. ret.push(state.address[i].location.address+state.address[i].detailAddress)
  31. }
  32. return ret
  33. }
  34. }
  35. }