解决方案:
1、在项目的config.js文件添加以下配置
proxy: {
'/api': { //需要代理的接口
target: 'http://localhost:8081',//springboot的端口号
changeOrigin: true, //是否跨域
ws: true, //是否代理 websockets
secure: true, //是否https接口
pathRewrite: { //路径重置
'^/api': ''
}
},
},
},
2.在vue文件编写请求
created(){
axios.get('api/user/findUserAll').then(function (resp) {
console.log(resp)
})
},