Skip to content
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

Access vue root instance from within a module action #1645

Closed
seminarian opened this issue Nov 16, 2019 · 7 comments
Closed

Access vue root instance from within a module action #1645

seminarian opened this issue Nov 16, 2019 · 7 comments

Comments

@seminarian
Copy link

@seminarian seminarian commented Nov 16, 2019

What problem does this feature solve?

The possibility to use root vue instance methods from within the actions of modules.

Within actions of vuex (not in modules) the vm can be accessed by this._vm .. See #1399

I can't succeed doing this from a module action. this is just the exports defined in the module file..

What does the proposed API look like?

I'm not sure.. There's more clever minds than me to solve this..

@ktsn

This comment has been minimized.

Copy link
Member

@ktsn ktsn commented Nov 17, 2019

Please answer the first section of the issue template with proper use case. “I want to do this” doesn’t describes the justification.

@seminarian

This comment has been minimized.

Copy link
Author

@seminarian seminarian commented Nov 17, 2019

Same justificiation as in the Issue i referred to. Using a $notification or $axios method that got installed on the instance.

@seminarian

This comment has been minimized.

Copy link
Author

@seminarian seminarian commented Nov 17, 2019

I've done it this ("dirty"?) way:
export let vm = new Vue({ el: '#app', router, store, template: '<App/>', components: { App } })

and in module file..
import {vm} from '../../main'

@ktsn

This comment has been minimized.

Copy link
Member

@ktsn ktsn commented Nov 18, 2019

  1. You don't need to (and should not) access them via Vue instance. Just access them directly by importing it.
  2. If you are talking by SSR context, you should extend store instance (this in action) as Nuxt does.
@ktsn ktsn closed this Nov 18, 2019
@seminarian

This comment has been minimized.

Copy link
Author

@seminarian seminarian commented Nov 18, 2019

  1. Okay.. If you say so
  2. is wrong. If you do this in the action in a module, it's a reference to the module file, not the store instance..
@ktsn

This comment has been minimized.

Copy link
Member

@ktsn ktsn commented Nov 19, 2019

If you do this in the action in a module, it's a reference to the module file, not the store instance..

You probably use arrow function in that case. Don't use it if you want to use this as it binds this value with the one under declared context.

@seminarian

This comment has been minimized.

Copy link
Author

@seminarian seminarian commented Nov 19, 2019

You are right! Thank you very much for clearing that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.