react截取地址栏的id并请求接口

  //初始化请求
   componentWillMount() {
		        const { location } = this.props;
		        const parse = queryString.parse(location.search.replace('?', ''));
		        this.setState({ id: parseFloat(parse.id) })
	  }
   //页面挂载请求
      componentDidMount(){
			        home.Gonggao({id:this.state.id}).then((result)=>{
			        if(result.code===1){
			        this.setState({
			        data:result.data[0]
			        })
			        }else{Toast.offline(result.msg,1)}
			        })
	 }

你可能感兴趣的:(javascript)