本地调试下令行中执行(我项目是用的yarn来运行):yarn run dev,发现接口可以请求拿到数据了。但在线上生产情况下还是会报错,如果只需要本地调试那到这里就完成了!!!
接下来处理生产情况(线上模式)下的跨域报错题目,由于刚刚前端的配置中已经加上了对生产情况的代理配置,其实也就是根目录下的这个文件【.env.production】。
7.本地连接上服务器,且服务器已配置好Nginx,找到Nginx的运行配置文件【nginx.conf】,内容大抵如下(注意看注释):
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
client_max_body_size 20M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include