Vue - 为什么我不能在 vuex 中显示我的 axios get 请求的结果?

马赫迪·托西

我正在使用 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用vuex在vue 2 JS中的Axios拦截器

为什么我不能在std :: transform中使用std :: get <0>?

在Vuex模块操作中访问vue-axios

Axios请求拦截器在我的Vue应用程序中不起作用

为什么我不能在VueJS / Vuex中调用命名空间的getter?

Vue和Axios发出请求并显示结果

我无法在AXIOS中发出GET请求?

Vuex中的Axios Get with Header-NUXTJS

Vuex:Axios GET请求在组件内部返回未定义

为什么我不能在Vue中访问html canvas?

Vue使axios GET并使用键值显示数组中的数据?

为什么我可以在vuex操作中使用dayJS但不能在Vuex存储中初始化状态?

在Vue JS中遍历axios.get请求内的对象

为什么我不能在React中使用axios从localhost:3000调用localhost localhost:5000

为什么我的sql命令在ACCESS中显示正确的结果时不能在asp上运行?

为什么我不能在 Retrofit 上向拦截器请求 OkHttp 添加标头?

为什么我不能在 Flatlist 中显示我的项目?

为什么我不能在 cookie.get 函数之外使用 cookie 变量值?

Vue:为什么我不能在组件模板中使用 refs?

为什么我不能在我的 Vue 应用程序上使用 debugger 或 console.log

在 Vuex 中 axios 请求成功后显示通知

为什么我的 axios GET 请求会收到 [object Object]?

为什么我不能在 LaTeX 中显示 ð 符号?

如何解决Vue中的Axios GET请求404错误?

为什么我不能在 for 循环中打印每个结果?

为什么我不能在 html 中全屏显示图像?

我想用这个。$ axios 与 Vuex 常量

为什么我不能在我的回调中调用我的 vue 组件的函数

Vue js vuex 无法在我的循环中显示我的数据