admin管理员组

文章数量:1794759

“Access

“Access

Access-Control-Allow-Credentials跨域问题

  • 在前端向后端请求接口数据时在控制台报出错误:
  • 解决方法:前端: 在config文件下的index.js中`
  • module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'localhost:后端设置的端口号', ws: true, changeOrigin: true, pathRewrite: { '^/api': '' } } }

    在后端也要配置跨域请求:

    @Override public void addCorsMappings(CorsRegistry registry) { //所有请求都允许跨域 registry.addMapping("/**") .allowCredentials(true) //添加起源 .allowedOrigins("localhost:前端端口号") .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") .allowedHeaders("*") .maxAge(3600); }

    注意的是不要忘记添加前端起源 3. 配置完之后问题就得到了解决

    本文标签: Access