赞
踩
网上乱七八糟的教程没一个能用的,配置nginx即可解决跨域问题,本地+服务器通用
添加nginx配置:
server
{
listen 80;
server_name my.xxx.com;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;
add_header 'Access-Control-Allow-Method' *;
}
axios请求方法:
async true_device () {
const { data: res } = await this.$http.post('http://my.xxx.com/api8/xxx.php', data)
console.log(res.code)
}
修改完后测试获取正常!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。