vue前後臺跨越請求簡單總結

##vue-cli請求數據注意事項

vue-cli使用的Proxying

代理配置

/*config/index.js */
    proxyTable: {
    //像這裏我接口是http://www.xxxx.x.xxx:8080/portal/role/roles
      '/portal': { 
     // /portal只要含有這個的就是我們要委託的url
        target:   'http://www.xxxx.x.xxx:8080',
        //target:被請求的地址
        changeOrigin:true,
       //changeOrigin 是否代理

api.js配置

 axios.defaults.withCredentials=true;/*設置session共享配合後臺使用 */

後臺配置

CorsConfiguration corsConfiguration = new CorsConfiguration();  
        corsConfiguration.addAllowedOrigin("*");//這個指點可以進來的地址
        corsConfiguration.addAllowedHeader("*");  
        corsConfiguration.addAllowedMethod("*");  
        corsConfiguration.setAllowCredentials(true);//共享session配合前端使用

僅供參考, 實測有用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章