vue 跨域(笔记)

vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No 'Access-Control-Allow-Origin' header is present on the requested resource.” 这种跨域错误。

解决:

1、后台

header('Access-Control-Allow-Origin:*');//允许所有来源访问 

header('Access-Control-Allow-Method:POST,GET');//允许访问的方式   

2、前台

打开config/index.js,在proxyTable中添写如下代码:

猜你喜欢

转载自blog.csdn.net/qq_38388578/article/details/83089864