vue實現跨域請求的設置


vue實現跨域請求,需要在vue.config.js里添加以下設置
     proxy: {
      '/service/rest': {    
        target: 'http://localhost:8080/autotable/service/rest',
        ws: true,
        changeOrigin: true,
        pathRewrite:{
            '^/service/rest':''
        }
    }
  }
其中 ,將changeOrigin設置為true,就不會存在無法跨域請求的問題了。
然后就可以直接在下面引用axios調用了。
import axios from '@/api/api';
export default {
    userList(params) {
        return axios.post('service/rest/api/user/logincode', params);
    },
  
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM