在最外层的app.vue中有这么一段代码
created: function() {
this.getTopNav()
router.beforeEach((to, from, next) => {
next()
//路由变化时执行
if(to.name !== from.name){
this.getTopNav()
console.log(222)
this.$store.dispatch('FECTH_ISLOGINED')
}
})
}
这是store.js
const actions = {
//是否已登录
FECTH_ISLOGINED: function({commit}){
axios.get('/account/user/islogined').then(res => {
commit('TOGGLE_ISLOGINED', { all: res.data.isLogined});
}).catch(err => console.log(err))
}
}
路由变化时console只输出了一次,但是this.$store.dispatch('FECTH_ISLOGINED'),打开控制台看到实际上发起了两个ajax请求,求大神帮看下?不胜感激
希望采纳 可以给其他人看
两次请求分别返回204和200
下面是百度百科对于204返回码的说明
然后说原因
axios用的是ES6的Promise
等你查完这两个就可以知道具体为什么了 - 表示也是今天勉强知道大概为什么 但是可能因为基本功不扎实 所以还是不知道怎么表述 希望采纳 给其他人一个引路针