dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

effect 中调用类的方法时,`this` 指向 `null` #2412

Closed wangming-0215 closed 3 years ago

wangming-0215 commented 3 years ago
class AuthService extends HttpClient {
  login(params: LoginParamsType) {
    console.log(this);
    return this.post('/api/login/account', { data: params });
  }

  getCaptcha(mobile: string) {
    return this.get(`/api/login/captcha?mobile=${mobile}`);
  }
}

export const authService = new AuthService();

// auth.model.ts

yield call(authService.login, payload)

effect 中调用yield call(authService, payload) 时,authService 中的 this 指向 null