【发布时间】:2019-01-05 23:00:32
【问题描述】:
我正在使用 Laravel、vue、vuex 和 axios
我正在尝试从数据库中获取数据并显示在我的组件中
这是我的lists.vue 文件
<specialist v-for="doctor in DoctorsPerDayData" :key="doctor.id">
<template slot="speciality">
<a class=" button specialist" @click="clicked(doctor)">
<strong>
{{ doctor.speciality}}
</strong>
</a>
</template>
<template slot="doctor">{{ doctor.name}}</template>
</specialist>
我正在测试注释代码,但仍然得到相同的结果
computed: {
// ...mapGetters([
// 'DoctorsPerDayData'
// ]),
// DoctorsPerDayData (){
// return this.$store.state.DoctorsPerDay
// }
DoctorsPerDayData : {
get(){
return this.$store.state.DoctorsPerDay
}
}
methods:{
...mapActions([
'UpdateDoctorsPerDay'
]),
},
mounted() {
this.UpdateDoctorsPerDay();
}
这是我的store.js 文件
export const store = new Vuex.Store({
state:{
DoctorsPerDay: null,
},
getters:{
DoctorsPerDayData: state => {
return state.DoctorsPerDay
}
},
mutations:{
UpdateDoctorsPerDay(state , DoctorsPerDay ){
state.DoctorsPerDay = DoctorsPerDay;
}
},
actions:{
UpdateDoctorsPerDay: ({commit})=>{
axios.get('/get/Doctors/date')
.then((response) => {
commit('UpdateDoctorsPerDay', response.data)
})
},
}
});
另一方面,我的 vuex 开发工具显示 DoctorsPerDay 有数据
我没有收到任何错误:|
【问题讨论】: