Vue跨域请求配置,避免再次踩坑

1.配置config->index.js
	// dev: 中
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {		// 这个api为自定义的字符串,相当于'/api' == 'http://192.168.123.130:9979'
          target: 'http://192.168.123.130:9979',	// 需要跨域的地址以及端口名,后面不能带/
          changeOrigin: true,		//是否跨域
          pathRewrite: {
              '^/api': '/'		//这里相当于用/代替target中的地址,使用时get('/api/login')
          }
      }
    },

你可能感兴趣的:(vue)