问题背景
在前端访问资源会提示:*** has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这时就需要配置nginx代理来访问跨域资源。
Nginx配置
1 | location /getjoke { |
配置后执行:
1 | nginx -s reload |
前端代码(vue)
1 | showJoke: function () { |
And the truth will set you free.
在前端访问资源会提示:*** has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这时就需要配置nginx代理来访问跨域资源。
1 | location /getjoke { |
配置后执行:
1 | nginx -s reload |
1 | showJoke: function () { |