vue中全局路由守卫中替代this(this.$store/this.$vux)

全局路由守卫this.$vux.loading.hide()报错,访问不到this

解决办法
申明变量代替this
main.js文件方法

router.beforeEach((to, from, next) => {
	if(vue){
		vue.$vux.loading.hide()
	}else{

	}
  next()
})

let vue = new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

if判断防止第一次初始化报错

或者

let vue = new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
router.beforeEach((to, from, next) => {
	// if(vue){
		vue.$vux.loading.hide()
	// }else{

	// }
  next()
})

猜你喜欢

转载自blog.csdn.net/qq_40557812/article/details/84940273
今日推荐