1 一般的fetch用法
|
|
具体的栗子如下
|
|
2 参数解析
url 地址: ‘./path’
option :
method(String) - HTTP request method. Default:"GET"body(String, body types) - HTTP request bodyheaders(Object, Headers) - Default:{}credentials(String) - Authentication credentials mode. Default:"omit"``"omit"- don’t include authentication credentials (e.g. cookies) in the request"same-origin"- include credentials in requests to the same site"include"- include credentials in requests to all sites
Response
Response represents a HTTP response from the server. Typically a Response is not constructed manually, but is available as argument to the resolved promise callback.
Properties
status(number) - HTTP response code in the 100–599 rangestatusText(String) - Status text as reported by the server, e.g. “Unauthorized”ok(boolean) - True ifstatusis HTTP 2xxheaders(Headers)url(String)
Body methods 注意每个方法返回的都是一个Promise对象,
Each of the methods to access the response body returns a Promise that will be resolved when the associated data type is ready.
text()- yields the response text as Stringjson()- yields the result ofJSON.parse(responseText)blob()- yields a BlobarrayBuffer()- yields an ArrayBufferformData()- yields FormData that can be forwarded to another request
Other response methods
clone()Response.error()Response.redirect()