栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

来自React / Redux应用程序中组件的权限检查

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

来自React / Redux应用程序中组件的权限检查

onEnter 很棒,在某些情况下很有用。但是,以下是onEnter无法解决的一些常见身份验证和授权问题:

  • 根据Redux存储数据确定身份验证/授权(有一些解决方法)
  • 如果商店更新(但不是当前路由),请重新检查身份验证/授权

  • 如果子路由在受保护的路由下更改,请重新检查身份验证/授权

另一种方法是使用高阶组件。

您可以使用 Redux-auth-wrapper提供的高阶组件,以便于组件读取和应用身份验证和授权约束。


  • 要获取子方法,可以使用:

    refs, callback and callback from refs

  • 要获得儿童道具,您可以使用:

    this.refs.child.props.some or compInstance.props.some

方法和道具示例:

class Parent extends Component {    constructor(props){        super(props);        this.checkChildMethod=this.checkChildMethod.bind(this);        this.checkChildMethod2=this.checkChildMethod2.bind(this);        this.checkChildMethod3=this.checkChildMethod3.bind(this);    }    checkChildMethod(){        this.refs.child.someMethod();        console.log(this.refs.child.props.test);    }    checkChildMethod2(){        this._child2.someMethod();        console.log(this._child2.props.test);    }    checkChildMethod3(){        this._child3.someMethod();        console.log(this._child3.props.test);    }    render(){        return ( <div>     Parent     <Child ref="child" test={"prop of child"}/>     <ChildTwo ref={c=>this._child2=c} test={"prop of child2"}/>     <ChildThree returnComp={c=>this._child3=c} test={"prop of child3"}/>     <input type="button" value="Check method of child" onClick={this.checkChildMethod}/>     <input type="button" value="Check method of childTwo" onClick={this.checkChildMethod2}/>     <input type="button" value="Check method of childThree" onClick={this.checkChildMethod3}/> </div>        );    }}class Child extends Component {    someMethod(){        console.log('someMethod Child');    }    render(){        return (<div>Child</div>);    }}class ChildTwo extends Component {    someMethod(){        console.log('someMethod from ChildTwo');    }    render(){        return (<div>Child</div>);    }}class ChildThree extends Component {    componentDidMount(){        this.props.returnComp(this);    }    someMethod(){        console.log('someMethod from ChildThree');    }    render(){        return (<div>Child</div>);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413347.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号