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

mapGetter dosen't work with namespaced module #1657

Closed
andywuzh opened this issue Dec 16, 2019 · 1 comment
Closed

mapGetter dosen't work with namespaced module #1657

andywuzh opened this issue Dec 16, 2019 · 1 comment

Comments

@andywuzh
Copy link

@andywuzh andywuzh commented Dec 16, 2019

Version
3.1.2

Steps to reproduce

// store/modules/todo.js
export default {
  namespaced: true,
  state: {
    todos: [
      { id: 1, title: 'something todo' }
    ]
  },
  getters: {
    getTodo: state => id => state.todos.filter(todo => todo.id === id)[0]
  }
}


// a component.vue
methods: {
  ...mapGetters('todo', ['getTodo']),
  someMethod: {
    console.log(this.getTodo(1))

    // this work!
    console.log(this.getTodo()(1))
  }
}

What is expected?

this.getTodo(1) should return {id: 1, title: 'something todo'}

What is actually happening?

it return a callable function same as getTodo:

ƒ (id) {
  return state.filter(function (s) {
    return s.id == id;
  })[0];
}

There is no more details about how to use mapGetters with namespaced module in the doc.
Am I miss something or it should not be used in this way?

@vue-bot

This comment has been minimized.

Copy link

@vue-bot vue-bot commented Dec 16, 2019

Hello, thank you for taking time filling this issue!

However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).

I hope to see your helper-created issue very soon!

@vue-bot vue-bot closed this Dec 16, 2019
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.