Vue开发环境跨域访问

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/

posted @ 2020-01-21 11:30  芋头猪爸爸  阅读(359)  评论(0编辑  收藏  举报
我的主页