springboot vue (跨域問題)

2021-08-15 03:27:16 字數 1015 閱讀 6532

在後端使用spring boot。spring boot跨域非常簡單,只需書寫以下**即可。

@configuration

public class customcorsconfiguration 

@bean

public corsfilter corsfilter() 

}

spring boot應用用nginx反向**。而前端跨域請求的需求不減。

nginx跨域也比較簡單,只需新增以下配置即可。

location / 

if ($request_method = 'post')

if ($request_method = 'get')

}其中:add_header 'access-control-expose-headers'務必加上你請求時所帶的header。

例如本例中的「token」,其實是前端傳給後端過來的。如果記不得也沒有關係,瀏覽器的偵錯程式會有詳細說明。

chrome、firefox本身是可以通過配置支援跨域請求的。

先設定 axios

證明是ajax

請求psot 請求加入

headers

:

設定config 檔案下面的index.js 然後就可以再其它頁面訪問了

springboot vue (跨域問題)

if request method get 其中 add header access control expose headers 務必加上你請求時所帶的header。例如本例中的 token 其實是前端傳給後端過來的。如果記不得也沒有關係,瀏覽器的偵錯程式會有詳細說明。chrome firefox...

SpringBoot vue 解決跨域問題

非常簡單的前端呼叫的測試介面 public string login pathvariable username string username,pathvariable password string password 首先專案前端入口main.js import apiconfig from c...

Spring Boot Vue一步跨域

前段時間做個spring boot vue的小工程發現自己已經忘記的怎麼跨域請求 接收資料了。在工程中建立乙個包放進去,工程編譯既可自動使用。package com.study.it.util import org.springframework.context.annotation.configu...