【发布时间】:2020-06-22 18:09:43
【问题描述】:
我无法理解 mapGetters 如何使用 TypeScript。我正在关注示例here,但无法使用建议使其工作
这是我的代码
getters.ts
export const GET_POSTS = 'GET_POSTS'
posts.module
import {GET_POSTS} from '../types/getters'
...
get [GET_POSTS]() {
return this.posts || [];
}
PostsList.vue
@Component({
components: { PostListItem },
computed: mapGetters(["GET_POSTS"]) // what local prop does this map to or how do I access it?
})
export default class PostsList extends Vue {
name = "PostsList";
posts = [];
/**
* Get posts
*/
async mounted() {
console.log(this.GET_POSTS); // ERROR: Property 'GET_POSTS' does not exist on type 'PostsList'.
}
基本上,我正在尝试做:
...mapGetters({
posts: GET_POSTS
})
console.log(this.posts)
【问题讨论】:
标签: typescript vue.js vuex