0

下面是我正在使用的方法,我在下面的方法中做错了什么?请告诉我。

      private async GetLists(): Promise<any>
          {
          console.log("Hitting GetLists Method");
       return await 
          this.context.spHttpClient.get(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists`, 
            SPHttpClient.configurations.v1,{
             headers: [
                ['accept', 'application/json;odata=nometadata'],
                        ['odata-version', '']
                    ]
                   }).then((data) => 
                 {
                        //console.log("Total number of lists are " + data.length);
                                 return data;
                    });
                    }
4

2 回答 2

0

我的测试代码供您参考:

private GetLists(): Promise<any> {

    return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + "/_api/web/lists", SPHttpClient.configurations.v1,{
      headers: [
         ['accept', 'application/json;odata=nometadata'],
                 ['odata-version', '']
             ]
            })

      .then((response: SPHttpClientResponse) => {
        
        return response.json();

      }).then(response=>console.log(response));

  }

测试结果: 在此处输入图像描述

于 2021-02-08T07:28:56.903 回答
0

尝试使用 PnPjs:

private GetLists(): Promise<any> {
    return sp.web.lists.get().then((data) => {
      console.log("Total number of lists are " + data.length);
      return data;
    });
}

https://pnp.github.io/pnpjs/getting-started/

于 2021-02-09T12:29:49.417 回答