-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create store in component? #16
Comments
// @/store/index.ts
import {Store} from 'vuex'
export default store = new Vuex.Store({}) // @/components/mycomponent.ts (or .vue <script> portion)
import {Component, Vue} from 'vue-property-decorator'
import store from '@/store/index.ts'
import {VuexModule} from 'vuex-module-decorators'
@Module({dynamic: true, namespaced: true, name: 'mymodule', store})
class MyModule extends VuexModule {
somestuff = 'awesome stuff'
@Mutation
doSomething() {}
}
const mm = getModule(MyModule)
@Component
export default class MyComponent extends Vue {
somedata = mm.somestuff
somemethod() { mm.doSomething() }
} |
Is there a way to do this where I can instantiate the module manually.
There are some cases where I need to create them on demand and share their
state across multiple components. I'd also need to unregister them.
Great job so far btw, this is an amazing expansion to the other decorator
libraries!
|
You mean do the |
Yes @championswimmer |
Would I be able to do |
If you do not mark is dynamic then you can import the module class and register it into the store. // @/store/moduleA.ts
@Module
export default class ModuleA extends VuexModule {
} // @/components/Comp.vue
import ModuleA from '@/store/moduleA'
this.$store.registerModule('name', ModuleA) |
I this case, how do you access the module from the component? Can you use getModule() and benefiting from the typing, intellisense, etc.?
|
How can I create stores at runtime on demand? I have some pages that need to have their own specific namespaced modules
The text was updated successfully, but these errors were encountered: