码迷,mamicode.com
首页 > 其他好文 > 详细

Vue proxy

时间:2018-11-07 23:10:53      阅读:434      评论:0      收藏:0      [点我收藏+]

标签:文件   comm   strong   代理   api   vue   打开   local   www.   

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\etcmac则直接前往文件夹/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  跨域地址
 

Vue proxy

标签:文件   comm   strong   代理   api   vue   打开   local   www.   

原文地址:https://www.cnblogs.com/shui1993/p/9926148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!