vue跨域请求数据配置

1、在config>index.js里面配置proxyTable

1   proxyTable: {
2       '/api': {
3          target: '要访问的接口地址',  //线上,线下的接口地址都可以
4          changeOrigin: true,
5          pathRewrite: {
6            '^/api': ''
7          }
8        }
9     },

2、安装一个插件代理

npm install --save-dev http-proxy-middleware

3、

    this.$http.post('/api/channel.action', cxParam).then((res) => {
   // api对应config>index.js里面配置的api,(可自行定义)
   //这样定义的接口地址会自动拼接到 ‘http://要访问的地址/channel.action’,.... 
})