欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue前后端不同端口的實現(xiàn)方法

 更新時間:2018年09月19日 14:55:03   作者:Simpleelegant  
今天小編就為大家分享一篇Vue前后端不同端口的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

前端Vue 8080端口,后端Node.js 8085端口 主要記錄下前后端不同端口遇到的問題

1、寫服務(wù)器端程序,我的在(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();
 }
});

這段代碼很重要,要是沒有的話會出現(xiàn) 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~\(≧▽≦)/~啦啦啦~

以上這篇Vue前后端不同端口的實現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論