且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在单文件组件中正确使用Vue Router之前的RouteEnter或Watch触发方法?

更新时间:2023-10-29 20:19:16

Since you want to re-populate search results each time a user visits the route.

You can use beforeRouteEnter() in your component as below:

beforeRouteEnter (to, from, next) { 
  next(vm => { 
    // access to component's instance using `vm` .
    // this is done because this navigation guard is called before the component is created.            
    // clear your previously populated search results.            
    // re-populate search results
    vm.initializeSearch();
    next();
  }) 
} 

You can read more about navigation guards here

Here is the working fiddle

相关阅读

推荐文章