美文网首页
vue更改端口和跨域设置

vue更改端口和跨域设置

作者: 名刀工一品 | 来源:发表于2020-03-03 00:25 被阅读0次

    1.更改端口的监听

    找到config文件夹下面的index.js打开后找到port:并修改

    (图片防盗链:图片接口没错,但是总是报403错误,只需要再index.html中添加上

    <metaname="referrer"content="never">

    可以无视接口的限制

    2.跨域设置

    1.前端解决:找到config文件夹下面的index.js打开后找到proxyTable,改为

    proxyTable: {

    '/api': {

    target:'http://www.abc.com',//目标接口域名

    changeOrigin:true,//是否跨域

    pathRewrite: {

    '^/api':'/api'//重写接口

         }

       },

    cssSourceMap:false

    }

    2.后端解决:(express为例)

    //设置允许指定域名“http://www.zhangpeiyue.com”跨域:

    app.use("*",function(req,res,next){

    //设置允许跨域的域名,*代表允许任意域名跨域

    res.header("Access-Control-Allow-Origin","http://www.zhangpeiyue.com");

    //允许的header类型

    res.header("Access-Control-Allow-Headers","content-type");

    //跨域允许的请求方式

    res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");

    }

    相关文章

      网友评论

          本文标题:vue更改端口和跨域设置

          本文链接:https://www.haomeiwen.com/subject/hiznkhtx.html