Closed zhezi closed 4 years ago
刚才试了在线预览的,没出现这问题啊,具体操作步骤是啥
1.修改vue中src/config/index.js apiPrefix:'/' 2.npm run serve 3.启动后端local服务
首先,此问题应该只会出现在开发阶段。
如果非要用'/'
的话,那么把config.js
里的route.mode
改为'hash'
。
原因也简单,比如登录页地址是'http://localhost/login'
,那么在你刷新或者在浏览器地址栏键入并回车时,会向devServer
发送一个'/login'
的get
请求,'/login'
会被设置的apiPrefix
匹配,所以devServer
会把这个请求转发给后端服务,由于这个请求并不是axios
发出的,所以请求头上没有带校验用户身份的标识,从而被拦截。退一万步讲,即使带上了身份标识,后端也会返回404页面。
{"msg":"请登录后重试","status":401,"success":false}