4.Vue跨域session問題解決


1.設置koa2服務器從本地代理轉發
修改:項目/config/index.js-->dev中
proxyTable: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
pathRewrite: { //需要rewrite重寫的, 如果在服務器端做了處理則可以不要這段
'^/api/': ''
}
}
},

//--------------------------------------------------
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
pathRewrite: { //需要rewrite重寫的, 如果在服務器端做了處理則可以不要這段
'^/api/': ''
}
}
},
//--------------------------------------------------

2.axios訪問路徑改為:
axGet('/api/hall/getRoomList',{},function(res){
alert(res.data);
},function(err){
alert(err);
});

3.一定要重啟vue服務器


免責聲明!

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



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