vuex.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. let k = keys.map((el,index)=>{
  22. let f = el.split('/');
  23. let tst = {}
  24. if(f.length==1){
  25. tst[el]=g[el]
  26. }else{
  27. tst[f[1]]=g[el]
  28. // tst[f[0]+'_'+f[1]]=g[el]
  29. // tst[f[0]][f[1]] = g[el]
  30. }
  31. return tst
  32. })
  33. let rulst = {};
  34. k.forEach(el=>{
  35. rulst = {...rulst,...el}
  36. })
  37. return rulst;
  38. }
  39. commit(funName,arg){
  40. try{
  41. this.store.commit(funName,arg);
  42. }catch(e){
  43. console.error("未发现函数方法:"+funName)
  44. }
  45. }
  46. actions(funName,arg){
  47. try{
  48. return this.store.dispatch(funName,arg);
  49. }catch(e){
  50. console.error("未发现函数方法:"+funName)
  51. }
  52. }
  53. //获得原始vuex对象。
  54. getVuex(){
  55. return this.store;
  56. }
  57. }
  58. export default vuex;