npm run dev 我们访问的是localhost:8080
config文件夹下的index.js配置文件的dev
dev: {
env: require('./dev.env'), port: 8080, autoOpenBrowser: true, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: {}, cssSourceMap: false },
服务器提供接口:https://www.exaple.com/server_new/login,提取域名:
https://www.exaple.com
proxy: {
'/apis': { //将www.exaple.com印射为/apis
target: 'https://www.exaple.com', // 接口域名 secure: false, // 如果是https接口,需要配置这个参数 changeOrigin: true, //是否跨域 pathRewrite: { '^/apis': '' //需要rewrite的, } } }
如果本身接口'/api'通用前缀,也就是说
https://www.exaple.com/api,可以把
pathRewrite删掉
此时已经设置好本地代理了
修改本地hosts
文件
window
文件路径一般是C:\Window\System32\drivers\etc
,mac
则直接前往文件夹/etc/hosts
,打开hosts
文件,在这一段下面把localhost
设置进去
# localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 activate.adobe.com 127.0.0.1 practivate.adobe.com 127.0.0.1 lmlicenses.wip4.adobe.com 127.0.0.1 lm.licenses.adobe.com 127.0.0.1 na1r.services.adobe.com 127.0.0.1 hlrcv.stage.adobe.com localhost www.exaple.com 跨域地址