下载querystring解析对象变为对象
yarn add querystring
import React, { Component } from 'react'
import qs from 'querystring'
export default class index extends Component {
postHttp=()=>{
fetch("http://iwenwiki.com/api/blueberrypai/login.php",{
method:"POST",
headers:{
"Content-Type":"application/x-www-form-urlencoded",
"Accept":"application/json,text/plain,*/*"
},
body:qs.stringify({
user_id:"iwen@qq.com",
password:"iwen123",
verification_code:"crfvw"
})
}).then(res=> res.json()
).then(data=>{
console.log(data)
})
}
render() {
return (
<div>
我是fetch
<button onClick={this.postHttp}>发送post请求</button>
</div>
)
}
}