有人可以给我代码来获取 spfx webpart 的当前登录用户吗?我不想要 pnp.sp 或 sp.web,我想使用 spHttpClient 等。
我在互联网上的任何地方都找不到基本代码。一个链接就可以了。
问候,
吨
有人可以给我代码来获取 spfx webpart 的当前登录用户吗?我不想要 pnp.sp 或 sp.web,我想使用 spHttpClient 等。
我在互联网上的任何地方都找不到基本代码。一个链接就可以了。
问候,
吨
示例代码:
import { SPHttpClient, SPHttpClientResponse,ISPHttpClientOptions} from '@microsoft/sp-http';
this.context.spHttpClient.get(`${this.context.pageContext.web.absoluteUrl}/_api/SP.UserProfiles.PeopleManager/GetMyProperties`,
SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) =>{
response.json().then((responseJSON: any) => {
console.log(responseJSON.DisplayName)
})
})