Javascript 如何在componentDidMount方法中传递多个函数
我正在做一个项目,我需要从后端获取用户数据和用户角色,所以我创建了两个类似这样的API调用Javascript 如何在componentDidMount方法中传递多个函数,javascript,reactjs,Javascript,Reactjs,我正在做一个项目,我需要从后端获取用户数据和用户角色,所以我创建了两个类似这样的API调用 loadUsers() { axios.get('http://127.0.0.1:8000/api/users') .then((response) => { this.setState({ users:response.data, }) }) } 为了获得角色,我创建了另一个方法 loadRoles() {
loadUsers() {
axios.get('http://127.0.0.1:8000/api/users')
.then((response) => {
this.setState({
users:response.data,
})
})
}
为了获得角色,我创建了另一个方法
loadRoles() {
axios.get('http://127.0.0.1:8000/api/roles')
.then((response) => (
this.setState({
roles:response.data,
})
))
}
但是当我在componentDidMount()
方法中调用这些方法时,我得到以下错误
./src/views/Base/Users/Users.js
Line 107: Expected an assignment or function call and instead saw an expression no-unused-expressions
Search for the keywords to learn more about each error.
这是我的州
constructor(props){
super(props);
this.state = {
users:[],
roles:[],
}
}
组件didmount
在哪里?显示如何调用它们componentDidMount(){this.loadUsers(),this.loadRoles()}
为什么它是逗号?提示:这是你的错误。107行有什么?它是一个渲染函数吗?我用逗号分隔每个函数