webpack配置解决跨域

webpack 配置

proxy:  {
      '/api/*': {
        target: 'http://localhost:8888/', // 目标服务器地址
        secure: false, // 目标服务器地址是否是安全协议
        changeOrigin: true, // 是否修改来源, 为true时会让目标服务器以为是webpack-dev-server发出的请求!
        // '/api/login' =>    target + '/login'
        pathRewrite: {'^/api': '/'} // 将/api开头的请求地址, /api 改为 /, 即 /api/xx 改为 /xx
      }
  }

我当前服务为  http://localhost:8080/

 fetch('/api/data').then(res => {
      // http://localhost:8888/data 实际访问地址
      console.log(res)
    })





猜你喜欢

转载自blog.csdn.net/dcxia89/article/details/79730183
今日推荐