ScopeStoreMixin.js
35 lines
| 1 | export default { |
| 2 | props: { |
| 3 | scope: { |
| 4 | type: String, |
| 5 | default: 'default', |
| 6 | }, |
| 7 | }, |
| 8 | methods: { |
| 9 | scopedName( name ) { |
| 10 | return 'scope-' + this.scope + '/' + name; |
| 11 | }, |
| 12 | getter( name, payload ) { |
| 13 | if ( !this.$store ) { |
| 14 | debugger; |
| 15 | } |
| 16 | const result = this.$store.getters[ this.scopedName( name ) ]; |
| 17 | |
| 18 | if ( 'undefined' !== typeof payload && 'function' === |
| 19 | typeof result ) { |
| 20 | if ( payload?.length && 'object' === typeof payload ) { |
| 21 | return result( ...payload ); |
| 22 | } |
| 23 | return result( payload ); |
| 24 | } |
| 25 | |
| 26 | return result; |
| 27 | }, |
| 28 | commit( name, payload ) { |
| 29 | return this.$store.commit( this.scopedName( name ), payload ); |
| 30 | }, |
| 31 | dispatch( name, payload ) { |
| 32 | return this.$store.dispatch( this.scopedName( name ), payload ); |
| 33 | }, |
| 34 | }, |
| 35 | }; |