老师帮我看下
来源:7-2 根据登录权限决定页面展示(2)
vivi_li
2020-08-30 23:34:09
//请求登录的返回结果是false
import React,{Component} from "react";
import axios from "../../api/request";
import { Redirect } from 'react-router-dom'
class Vip extends Component{
constructor(props) {
super(props);
this.state={
login:true
}
}
render() {
if (this.state.login){
return(
<div>vip</div>
)
}else {
return <Redirect to={'/'}/>
}
}
componentDidMount() {
axios.get('http://www.dell-lee.com/react/api/isLogin.json',{
withCredentials:true
}).then(res=>{
console.log(res.data)
this.setState({
login:res.data.login
})
})
}
}
export default Vip
1回答
好帮手慕慕子
2020-08-31
同学你好, 已经登录后,点击vip页面,返回的结果中login属性值为true。示例:
测试结果如下:
同学可以再测试下,祝学习愉快~
相似问题