Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

vue如何判断路由跳转以后,再执行一个方法

需求:点击按钮跳转页面,如何保证已经跳转到目标页面后,再执行方法fun()?
目标页面不固定,所以不想去各个页面里执行window.fun()

let path = this.getPath()  //path不固定
this.$router.push(path)
window.fun()

//使用$nextTick也不可以。
this.$nextTick(()=>{
  window.fun()
})

//使用setTimeout可以,但又不保险
setTimeout(()=>{
   window.fun()
},2000)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

搜vue全局路由钩子


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...