最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - VueJS: Cannot read property 'dispatch' of undefined - Stack Overflow

programmeradmin0浏览0评论

I start my simple project with VueJS and Vuex. And I have a problem witch calling method from store. When I click my button in console I see this error

Uncaught TypeError: Cannot read property 'dispatch' of undefined at VueComponent.onSignin

Here is my ponent with button which should call dispatch
Login ponent.

And here is my store index.js Vuex.Store

And here you can find full repo

I read many topics on another forum but I stil don't know why it is not work, because I do similar project few months ago and it works correctly.

I start my simple project with VueJS and Vuex. And I have a problem witch calling method from store. When I click my button in console I see this error

Uncaught TypeError: Cannot read property 'dispatch' of undefined at VueComponent.onSignin

Here is my ponent with button which should call dispatch
Login ponent.

And here is my store index.js Vuex.Store

And here you can find full repo

I read many topics on another forum but I stil don't know why it is not work, because I do similar project few months ago and it works correctly.

Share edited Sep 12, 2018 at 19:04 Bartlomiej Mroczek asked Sep 12, 2018 at 18:59 Bartlomiej MroczekBartlomiej Mroczek 1213 silver badges14 bronze badges 4
  • I have noticed that in the Login ponent you call this.$store.dispatch('signUserIn') but in your vuex store in the actions there is not such an action. The only action is onUserLogin . You should make an action called signUserIn – gijoe Commented Sep 12, 2018 at 19:07
  • Good attention, but it still doesn't work. I pushed again with correct name of action. – Bartlomiej Mroczek Commented Sep 12, 2018 at 19:24
  • Can you please make also an update in action signUserIn(payload) to signUserIn(context,payload) and remove methods attribute in vuex store – gijoe Commented Sep 12, 2018 at 19:34
  • Hmm I do this, and it still doesn't work. If I good remember you should have permission to update 'help' branch. Fell free to do this. – Bartlomiej Mroczek Commented Sep 12, 2018 at 19:58
Add a ment  | 

1 Answer 1

Reset to default 4

Your store should be:

export default new Vuex.Store({

and not

export const store = new Vuex.Store({

发布评论

评论列表(0)

  1. 暂无评论