前端请求后端接口时处理跨域:
1、修改config下index.js文件:
dev: {
assetsSubDirectory: 'static',
assetsPublicPath: '/',
host: 'localhost',
port: 8080,
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false,
proxyTable: {
"/api": {
target: "http://192.34.50.17:8080",
changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
pathRewrite: {
'^/api': ''
}
}
},
devtool: 'cheap-module-eval-source-map',
cacheBusting: true,
cssSourceMap: true
},
2、main.js中添加:
import axios from 'axios'
axios.defaults.baseURL = '/'
Vue.config.productio