mobx的store中有一个获取token的request,如果获取成功将跳转路由至'/',但是store中无法使用this.props.history.push('/')
尝试加一个state存储登录与否,但是不太好,有没有直接解决的方法?
// 请把代码文本粘贴到下方(请勿用图片代替代码)
class IssueStore {
@observable open_list = []@observable item = ''@observable isLogin = false@observable username = ''@observable password = ''@observable table_loading =true@computed get fullName() { const { firstName, lastName } = this; if (!firstName && !lastName) { return "Please input your name!"; } else { return firstName + " " + lastName; } }@computed get loginStatus(){ return loginStatus=this.isLogin; }@action queryToken() { NewRequest.request({ form: { "username": this.username, "password": this.password }, url: BaseUrl+'/api/api-token-auth/', success: function (res) { let str = JSON.parse(res); NewRequest.setStorage('token', str.token); NewRequest.setStorage('username',this.username ); this.isLogin=true }.bind(this), error: function () { message.error('信息错误,请重新登录!'); }.bind(this) }) }@action queryOpenList() { NewRequest.request({ user_method: 'List_open', url: BaseUrl + '/api/issue/', success: function (res) { var obj = JSON.parse(res); this.open_list=obj; this.table_loading=false; }.bind(this), error: function (res) { if(res.status==='401'){ } }.bind(this) }) }
}
希望能够直接在上面这个queryToken函数里直接进行路由跳转。
ibeautiful
慕丝7291255
相关分类