我正在按照以下结构构建一个应用程序:http: //vuex.vuejs.org/en/structure.html
我components/App.vue
是这样的:
<template>
<div id="app">
<course :courses="courses"></course>
</div>
</template>
<script>
import Course from './course.vue'
import { addCourses } from '../vuex/actions'
export default {
vuex: {
getters: {
courses: state => state.courses,
},
actions: {
addCourses,
}
},
ready() {
this.addCourses(this.fetchCourses())
},
components: { Course },
methods: {
fetchCourses() {
// what do I have to do here
}
}
}
</script>
如何获取数据并将其设置为state.courses
?
谢谢