你需要做一個反向代理的東西 ===> 打開你的vue項目的config文件夾下的index.js
找到以下代碼
dev: { proxyTable: { '/api': { target: 'http://ip地址', //這里面是你要訪問的IP地址 changeOrigin: true, //開啟代理 pathRewrite: { '^/api': '/api' } }
修改后:
dev: { proxyTable: { '/queue-admin': { // 使用"/queue-admin"來代替 API頭部,可隨意命名 //target: '...', // 源地址 本地開發的API頭部 target: "...", // 配置到服務器后端的API頭部 pathRewrite: { '^/queue-admin': '/queue-admin' // 路徑重寫,第一個與上面相同,第二個/queue-admin 為server.context-path(服務器的上下文) }, // 以下解決https 訪問問題。上面的可以訪問http changeOrigin: true, secure: false, headers: { Referer: '...' } } } }
Tips:配置完這里之后一定要重新啟動項目要不然會沒有效果