Vue 设置proxy后post请求失效,pending挂起

vue.config.js文件配置
proxy: {
    '/dev-api': {
        target: 'http://1x.xx.x.xxx:xxxx', //
        changeOrigin: true,
        pathRewrite: {
          '^/dev-api': ''
        },
        //第一种方法
        onProxyReq: function(proxyReq, req, res, options) {
          if (req.body) {
            const bodyData = JSON.stringify(req.body)
            // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
            proxyReq.setHeader('Content-Type', 'application/json')
            proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
            // stream the content
            proxyReq.write(bodyData)
          }
       }
   }
},
//第二种方法,注释这行
before: require('./mock/mock-server.js')

你可能感兴趣的:(vue功能,报错修正,vue.js,javascript,前端)