vue3解決CORS 錯誤


第一步

  //創建vue.config.js文件
  module.exports = {
  lintOnSave: false,//是否在保存時檢查
  devServer: {
    host: 'localhost',//本機ip
    port: 8081,//本機端口
    open: true,
    proxy: {
      '/api': {  //代理別名
        target: 'http://localhost:8001',   //代理目標值
        changeOrigin: true,
        secure: true,
        pathRewrite:{  //替換路徑中的/api
          '^/api':''
        }
        /*pathRequiresRewrite: {
          '^/api': ''
        }*/
      }
    },
    overlay: {
      warning: false,
      errors: true
    }
  }
}

第二步

//修改axios的默認根路徑
axios.defaults.baseURL = '/api';


免責聲明!

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



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