前后端分离的项目第一个遇到的拦路虎应该就是 前后端分离所导致的跨域问题了。在vue.js里面,前后端分离里面,前端可以做的事情有:
1.修改 config/index.js里面的proxy
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: './',
proxyTable: {
'/ssms':{
target:'http://localhost:8080', // 你请求的第三方接口
//target: 'http://10.61.129.85:8080',
changeOrigin:true,
pathRewrite:{
'^/ssms':''
},
}
},
在main.js里面
import Axios from 'axios'
//保持客户端访问服务器端时,保持session有效
Axios.defaults.withCredentials = true;
Axios.defaults.baseURL = '/ssms'
Axios.defaults.headers.post['Content-Type'] = 'applicatio