Vue中的反向代理

config下面的index.js文件
const ios = require('./os');

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {
        target: 'http://192.168.0.127:8890', // 跨域地址
        changeOrigin: true, //是否跨域
        secure: false //是否使用https
      }
    },

    host: {ip: ios.ip, org: 'linkName.com'}, /*localhost,192.168.0.37*/
    port: 2019, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: true,
    errorOverlay: true,
    notifyOnErrors: false,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    useEslint: false,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    devtool: '#cheap-source-map', //‘inline-source-map’
    cacheBusting: true,
    cssSourceMap: false,
  }
}
ios 文件
const interfaces = require('os').networkInterfaces();
let IPAdress = '';
for(let devName in interfaces){
  let iface = interfaces[devName];
  for(let i=0;i<iface.length;i++){
    let alias = iface[i];
    if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
      IPAdress = alias.address;
    }
  }
}

module.exports = { ip : IPAdress }
API请求
// 导入axios
import axios from 'axios'
axios.get('/api/v1/home/getIndexInfo').then(function(res){
          console.log(res);
});
收藏 (0)
评论列表
正在载入评论列表...
我是有底线的