国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue前后端不同端口的實現方法

2019-11-19 12:53:55
字體:
來源:轉載
供稿:網友

前端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~/(

主站蜘蛛池模板: 宁蒗| 鄂托克前旗| 潮州市| 迁安市| 香格里拉县| 枣阳市| 高要市| 南澳县| 梅河口市| 阿克陶县| 西华县| 富平县| 北安市| 花垣县| 合阳县| 通州区| 盐城市| 连城县| 峡江县| 天长市| 武宁县| 泗水县| 嘉定区| 博湖县| 九龙坡区| 镇江市| 兴安县| 屯门区| 乌审旗| 金坛市| 邳州市| 朝阳区| 南康市| 阿拉善右旗| 富裕县| 蒙自县| 西林县| 潞西市| 鹿邑县| 江门市| 大邑县|