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

Inline namespacing question. #66

Open
chinavane opened this issue May 4, 2022 · 2 comments
Open

Inline namespacing question. #66

chinavane opened this issue May 4, 2022 · 2 comments

Comments

@chinavane
Copy link

chinavane commented May 4, 2022

use createNamespacedHelpers is success.

import { useStore } from 'vuex';
import { createNamespacedHelpers } from 'vuex-composition-helpers';
const store = useStore();
const { useState } = createNamespacedHelpers(store, 'home');
const { count } = useState(['count']); // can get count value
console.log(count);

Inline namespacing get error.

import { useStore } from 'vuex';
import { useState } from 'vuex-composition-helpers';
const store = useStore();
console.log(store.state.home.count); // can get count value
const { count } = useState('home', ['count']); // can't get count value,count is undefined
console.log(count);
@davidmeirlevy
Copy link
Contributor

The global "useState" function can be used in several ways (yours isn't one of them):

  1. inside a setup function: useState(["home/count"])

  2. Outside of Vue components:
    useState(store, ["home/count"])

BTW, You can do:
const {customKey} = useState({customKey: "home/count"})

@davidmeirlevy
Copy link
Contributor

@chinavane BTW, it's preferable to ask questions on StackOverflow instead inside GitHub issues, since a question here will be converted to closed issue and wont help future developers that will meet the same question 🤓.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants