首页 > 其他 > 详细

Vue开发环境跨域访问

时间:2020-01-21 13:22:34      阅读:67      评论:0      收藏:0      [点我收藏+]

Vue开发环境跨域访问其他服务器或者本机其他端口,需要配置项目中config/index.js文件,修改如下

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: ‘static‘,
    assetsPublicPath: ‘/‘,
    proxyTable: {
      ‘/api‘:{
        target:‘http://192.168.1.99:8080/‘,
        changeOrigin:true,
        pathRewrite:{
          ‘^/api‘:‘‘
        }
      }
    },

其中主要是加入

  proxyTable: {
      ‘/api‘:{
        target:‘http://192.168.1.99:8080/‘,
        changeOrigin:true,
        pathRewrite:{
          ‘^/api‘:‘‘
        }
      }
    }

这样你通过axios 或fetche访问  /api/** 便相当于跨域访问了 http://192.168.1.99:8080/

Vue开发环境跨域访问

原文:https://www.cnblogs.com/wangpeili/p/12221160.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!