//客户端index.jsimport React from 'react';import ReactDOM from 'react-dom';import './index.css';import App from './App';import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<div><Router><Route path='/supplies/:client_id' component={App}></Route></Router></div>, document.getElementById('root'));App.jsclass App extends Component {
state = {users: [], products:[]};
steps = ['纺纱','织布','后整','检查入库','发货'];
componentDidMount() { console.log(this.props.params.client_id); //不对这里
fetch('/supplies/320001')
.then(res => res.json())
.then(products => this.setState({ products }));
}访问http://localhost:3000/supplies/320001http://localhost:3000/supplies/420001如何获取320001 或 420001
1 回答
FFIVE
TA贡献1797条经验 获得超6个赞
this.props.params.client_id你是在哪里定义的。 打印下this,看是不是当前组件的实例 另外打印下 this.props.match.params
添加回答
举报
0/150
提交
取消