1
0

vuex.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * 操作全局Vuex。
  3. * 作者:tmzdy
  4. * 时间:‎2021‎年‎10‎月‎14‎日
  5. * 联系:zhongjihan@sina.com
  6. *
  7. */
  8. class vuex {
  9. constructor(store) {
  10. this.store = store;
  11. }
  12. //链式调用
  13. state(){
  14. return this.store.state;
  15. }
  16. //链式调用
  17. getters(){
  18. let t = this;
  19. const g = this.store.getters
  20. let keys = Object.keys(g);
  21. console.log(keys)
  22. let k = keys.map((el,index)=>{
  23. let f = el.split('/');
  24. let tst = {}
  25. if(f.length==1){
  26. tst[el]=g[el]
  27. }else{
  28. tst[f[1]]=g[el]
  29. // tst[f[0]+'_'+f[1]]=g[el]
  30. // tst[f[0]][f[1]] = g[el]
  31. }
  32. return tst
  33. })
  34. let rulst = {};
  35. k.forEach(el=>{
  36. rulst = {...rulst,...el}
  37. })
  38. return rulst;
  39. }
  40. commit(funName,arg){
  41. try{
  42. this.store.commit(funName,arg);
  43. }catch(e){
  44. console.error("未发现函数方法:"+funName)
  45. }
  46. }
  47. actions(funName,arg){
  48. try{
  49. return this.store.dispatch(funName,arg);
  50. }catch(e){
  51. console.error("未发现函数方法:"+funName)
  52. }
  53. }
  54. //获得原始vuex对象。
  55. getVuex(){
  56. return this.store;
  57. }
  58. }
  59. export default vuex;