我尝试从“ userPrincipalName”中仅提取用户名,然后将其作为参数连接到Axios的调用中。
“ userPrincipalName”包含类似于[email protected]的电子邮件,我只需要串联“ apple”(我的意思是我只需要在“ @”之前的字符串)
我不明白我在拆分时的错误是什么。?
这是我的示例:
getData = () => {
const { userPrincipalName } = this.state.azureLoginObject;
this.setState({ isLoading: true, data: [] })
axios.get("https://rallycoding.herokuapp.com/api/music_albums",{ userPrincipalName }.split('@')[0])
.then(res => {
this.setState({
isLoading: false,
data: res.data
});
console.log(res.data);
});
}
似乎您是在对象上而不是在字符串上使用split方法。我已经更新了。如果没有帮助,请您更新错误。
axios.get("https://rallycoding.herokuapp.com/api/music_albums",{ userPrincipalName.split('@')[0]) }