vue设置跨域调接口报504,如何解决

以下是我设置的代理

proxyTable: {
  '/api': {
    target: 'http://192.168.2.12:8980/',//设置你调用的接口域名和端口号 别忘了加http
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
    }
  },
  

下面是我的ajax调用的接口:$ajax修改了原生链Vue.prototype.$ajax = axios

    this.$ajax.get('/api/axis2/services/otherExpenseListQueryOfficial.otherExpenseListQueryOfficialHttpSoap12Endpoint/getQuery', {
      params: {
        applier: _this.applier,
        number: _this.number,
        agency:_this.agency,
        status:_this.status,
        order:'',
        page:1,
        pageSize:_this.pageSize
      }
    })

控制台报错: [HPM] Error occurred while trying to proxy request /axis2/services/otherExpenseListQueryOfficial.otherExpenseListQueryOfficialHttpSoap12Endpoint/getQuery?applier=&number=&agency=%E9%99%88%E5%AE%B6%E8%BE%89&status=&order=&page=1&pageSize=20 from localhost:8980 to http://192.168.2.12:8980/ (ECONNREFUSED) (https://nodejs.org/api/errors...
浏览器报错:app.js:2972 GET http://localhost:8980/api/axis2/services/otherExpenseListQueryOfficial.otherExpenseListQueryOfficialHttpSoap12Endpoint/getQuery?applier=&number=&agency=%E9%99%88%E5%AE%B6%E8%BE%89&status=&order=&page=1&pageSize=20 504 (Gateway Timeout)
dispatchXhrRequest @ app.js:2972
xhrAdapter @ app.js:2806
dispatchRequest @ app.js:3379
Promise resolved (async)
request @ app.js:3198
Axios.(anonymous function) @ app.js:3208
wrap @ app.js:3619
getsearch @ app.js:9412
click @ app.js:95812
invoker @ app.js:103617
fn._withTask.fn._withTask @ app.js:103402
app.js:9440 Error: Request failed with status code 504

at createError (app.js:3310)
at settle (app.js:3461)
at XMLHttpRequest.handleLoad (app.js:2871)       
阅读 16.7k
3 个回答

设置proxyTable只是解决跨域问题。请求是应该仍旧需要带上请求路径,除非配置nginx。

// 你是不是要调这个接口?
this.$ajax.get('http://192.168.2.12:8980/api/axis2/services/otherExpenseListQueryOfficial.otherExpenseListQueryOfficialHttpSoap12Endpoint/getQuery'...

先确定192.168.2.128980服务开了没,没开服务的话会是504 (Gateway Timeout)pingIP不代表开了8980端口服务

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题