前后端分离实现跨域:1.模拟后端开发,拉取后端代码。(需要后端代码,无坑,效率低)2.前端启动web服务器,node服务器或nginx服务器。(前端免费,不用关心后端)nodeserver:proxyTable:{'/api':{target:'http://segmentfault.com',pathRewrite:{'^/api':''}}}1。例如ajax接口“/getMessage”和本地的“localhost:8080/getMessage”存在跨域问题。2.localhost:8080=>http://segmentfault.com,本地开启服务器实现代理。nginx服务器:http{server{listen8080;#localportserver_name本地主机;location~*/get*|post*{#nginx正则匹配(高度可定制)proxy_passhttp://segmentfault.com;#反向代理}}}1。比如ajax接口“/getMessage”和本地的“localhost:8080/getMessage”存在跨域问题。2.localhost:8080=>http://segmentfault.com,本地开启服务器实现代理。3、nginx反向代理更多配置见http://www.nginx.cn/115.html。参考:1.vue-cliproxyTable2.nginx搭建web服务器
