前端Vue 8080端口,后端Node.js 8085端口 主要記錄下前后端不同端口遇到的問題
1、寫服務器端程序,我的在(node_proxy/index.js)下
app.all('*', function (req, res, next) { res.header('Access-Control-Allow-Origin', req.headers.origin || '*'); res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization,/'Origin/',Accept,X-Requested-With'); res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); res.header('Access-Control-Allow-Credentials', true); res.header('X-Powered-By', ' 3.2.1'); res.header('Content-Type', 'application/json;charset=utf-8'); if (req.method === 'OPTIONS') { res.sendStatus(200); } else { next(); }});這段代碼很重要,要是沒有的話會出現 No 'Access-Control-Allow-Origin' header is present on the requested resource 錯誤。
2、在前端用axios寫get請求處理程序,寫在了Card模板下
mounted(){ axios.get(HOST) .then(response => { this.sed = response.data.data; }) }3、在config/index.js下配置proxyTable:
proxyTable: { '/seller': { target: 'http://localhost:8085', changeOrigin: true, pathRewrite: { '^/seller': '/seller' } } },4、分別啟動前后端,OK~/( 主站蜘蛛池模板: 璧山县| 长子县| 文水县| 交城县| 巴林左旗| 建德市| 响水县| 兴义市| 和龙市| 和顺县| 九龙县| 禹城市| 新昌县| 措美县| 张北县| 岫岩| 大姚县| 罗平县| 许昌县| 三原县| 内黄县| 葫芦岛市| 慈利县| 榆树市| 桐庐县| 石林| 汾阳市| 新竹县| 阿克| 左贡县| 洛扎县| 新源县| 班戈县| 南城县| 淮安市| 滦南县| 鹤岗市| 九江市| 廉江市| 中阳县| 杂多县|