首页 > 解决方案 > Vue,在 Vue JS 中向服务器发送带有标头配置的 GET 请求

问题描述

当在 vue js 组件中创建组件时,我想向具有以下标头的服务器发送 GET 请求:

我应该如何写这个请求?

卷曲:

-X GET "http://134.140.154.121:7075/rest/api/Time" -H "accept: application/json" -H "授权:承载 eyJhbGciOiJSUzI1NiIsImtpZCI6IkFZd21VU0Jvd2lxcVRSRG81NTctVFEiLCJ0eXAiOiJhdCtqd3QifQ.yywyw"

它发送的信息如下:

回复正文:

{“值”:{“值”:“字符串”}}

如何随请求一起发送标头和输出设置?

标签: javascriptvue.jsrequesthttp-headersrequest-headers

解决方案


  fetch("http://134.140.154.121:7075/rest/api/Time",{
        method:'GET',
        header:{
             'accept': 'application/json',
             'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkFZd21VU0Jvd2lxcVRSRG81NTctVFEiLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE1OTMfryyw'
        }
    })
.then(res => res.json())
.then(res => {
      // Use res
}

推荐阅读