1.设置koa2服务器从本地代理转发
修改:项目/config/index.js-->dev中
proxyTable: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
pathRewrite: { //需要rewrite重写的, 如果在服务器端做了处理则可以不要这段
'^/api/': ''
}
}
},

//--------------------------------------------------
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
pathRewrite: { //需要rewrite重写的, 如果在服务器端做了处理则可以不要这段
'^/api/': ''
}
}
},
//--------------------------------------------------

2.axios访问路径改为:
axGet('/api/hall/getRoomList',{},function(res){
alert(res.data);
},function(err){
alert(err);
});

3.一定要重启vue服务器

相关文章:

  • 2021-11-06
  • 2021-08-17
  • 2022-01-01
  • 2021-04-08
  • 2022-01-21
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-31
  • 2022-01-14
  • 2021-11-29
  • 2021-05-18
相关资源
相似解决方案