【问题标题】:Services in reduxredux 中的服务
【发布时间】:2017-08-29 16:12:42
【问题描述】:

我是 react/redux 的新手,我尝试从我的 sagas 上限调用服务上限,但是当我尝试调用 axios.get() 方法时,我总是得到一个 PromiseStatus = "pending" 的承诺和 PromiseValue= undefined,我已经尝试得到承诺,但我不知道该怎么做。

我的 Sagas.js

try
    {        
       let response = yield 
         StudentsService.getStudentByEmail(action.payload.studentUser)
        
        
            yield put({type: studentActionsTypes.STUDENT_DATA_SUCCESS, 
       studentResponse: response});
    }    
    catch (error)
    {
        console.log('El servicio me devolvió un error: ' + error.message);
        yield put({type: studentActionsTypes.STUDENT_DATA_ERROR});

    }

我的服务

 export class StudentsService
    {    
        static getStudentByEmail(email)
        {
            
            var userT = '';
    
            const state = {
                studentF: {
                    studentId: '',
                    studentFullName: ''
                }
            };
    
            let userPromise = UsersService.getUsers();
            userPromise.then((response) =>
            {
                if(response.data.users.length >= 0)
                {
                    response.data.users.map(u =>
                    {
    
                        if(u.email == email)
                        {
                            userT = u;
                            console.log('Nombre en este objeto: ' + userT.name)
                            this.state = {
                                studentF: {
                                    studentId: userT.id,
                                    studentFullName: userT.name + ' ' + userT.lastName
                                }
                            }
                            
                        }
                    });
                }
    
            });
    
    
            return state.studentF;
        }
    }

我会很感激你的帮助。

【问题讨论】:

  • 我试图做这样的事情来解决我的问题,但它不起作用:axios.get('/api/orig') .then(function (response) { obj. origs = response.data }) .catch(function (error) { console.log(error); });

标签: react-redux


【解决方案1】:

我能够用另一个question中的答案解决我的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 2019-10-02
    • 1970-01-01
    • 2021-07-26
    相关资源
    最近更新 更多