vue+thinkphp5 跨域问题

vue设置

Vue.config.productionTip = false
Vue.prototype.$http.config.headers={
	'content-type': 'application/x-www-form-urlencoded'
	// 'token':uni.getStorageSync('uuid')
}
Vue.prototype.$http.config.baseURL='XXX';

服务器 ng配置文件

add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
add_header Access-Control-Allow-Origin *; 

代码设置

header('Access-Control-Allow-Origin:*');
// 响应类型  
header('Access-Control-Allow-Methods:*');
// 响应头设置  
header('Access-Control-Allow-Headers:*');
if( $_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
   exit;
}
发布了65 篇原创文章 · 获赞 20 · 访问量 2110

猜你喜欢

转载自blog.csdn.net/weixin_43993175/article/details/103942303