Skip to content

I need clarifications about accessing the store actions in the return of the setup function #540

Discussion options

You must be logged in to vote

In JS, functions using this must be called wiht the object: store.someAction(), otherwise this (the context) won't have the same value.

Just return the whole store in setup:

    setup() {
        const settings = useSettingsStore();
        return {
-            setPlatformName : settings.setPlatformName,   // <= setPlatformName is a  simple action
+            settings,
        }
    }

And then do @click="settings.setPlatformName(theName)"

You can also do

setPlatformName: settings.setPlatformName.bind(settings)

To set the this value

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants