vue项目中前端解决跨域
在src同级创建vue.config.js中写入一下内容
module.exports = {
// 修改的配置
publicPath: '/',
lintOnSave: false,//忽略eslint语法错误
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000/',页面中需要替代的
changeOrigin: true,//允许跨域
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
同时在页面中所有axios请求中的url中的http://localhost:3000/
用api
替换