在根目录新建vue配置vue.config.js
// vue-cli 配置项
module.exports = {
publicPath:'/',
devServer: {
port: 8081,
proxy: {
'/api':{
target:'http://127.0.0.1:5000',
changeOrigin:true,
ws:true,
pathRewrite:{
'^/api':''
}
}
}
}
};
路由代码
export default {
name:"test",
data(){
return {info:""}
},
mounted () {
// console.log("hello")
this.axios
.get('/api/say?data=123')
.then(response => (this.info = response.data))
.catch(function () { // 请求失败处理
console.log("error");
});
}
}