一、接口跨域问题,开发阶段可使用此方式解决,生产环境要解决跨域问题。
devServer: {
open: true,
proxy: {
'/api': {
target: 'http://192.168.60.35:8083/', //
changeOrigin: true,
pathRewrite: {
'^/api': '/' //将http://192.168.60.35:8083/替换为/api
}
}
}
},
使用
login:(fn)=>{
axios.get(`/api`).then(res => {
back(res, fn)
})
},
效果请求地址为
http://192.168.60.35:8080/api
二、全局路由入口拦截
为避免app.vue文件里面代码未执行完毕,就执行另一个页面的文件
操作:全局路由入口拦截
在router/index.js文件中添加
import storeAlise from '../store'
router.beforeEach((to,from,next)=>{
if(storeAlise.state.loginSuccessful){
setTimeout(()=>{
next()
},100)
}else{
setTimeout(()=>{
next({path:'/'})
},100)
}
})