1. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
加上这个header,在method 是POST时,PHP可以使用 $_POST 获取,否则要使用 file_get_contents('php://input')。
2. axios.defaults.withCredentials = true;
跨域时,如果要使用Cookie,可以加上 withCredentials= true。
后端页面,也需要加上相应的 header。
header('Access-Control-Allow-Origin: http://localhost:8080');
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header('Access-Control-Allow-Headers:x-requested-with,content-type');
© 著作权归作者所有