我正在使用 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
有数据
我没有收到任何错误:|
为了测试创建一个新的 Laravel 项目并用 vue 和 vuex 做具体的例子,我看到它的工作!
结果,我只是制作了新的 Laravel 项目,然后一步一步地将我的文件移到那里,
它完美地工作:| ;)
对不起,我的英语不够好;)
祝你好运 ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句