fetch是由原生JS提供的
fetch( url ,{
method: ‘POST’,
body: JSON.stringify(data), // 传输的数据
headers: {
‘content-type’: ‘application/json’
},
mode: ‘cors’, // 跨域请求
}).then(res => {
return res.json();
}).then(json => {
console.log( json);
return json;
}).catch(err => {
console.log(err);
})
如果跨域请求,后台需配置:(“Access-Control-Allow-Origin”, “*”)