vue 浏览器滚动行为

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import {routes} from './routes'
Vue.use(VueRouter)

const router =new VueRouter({
  routes ,
  mode:'history',
  scrollBehavior(to,from,savedPosition){
    //浏览器滚动行为
    //return {selector:'.btn'};
    //return {x:0,y:100};
    if(savedPosition){
      return savedPosition;
    }else{
      return {x:0,y:0}
    }
  }
})
//全局守卫
/*router.beforeEach((to,from,next)=>{
  //alert("还没有登录,请先登录");
 // next();
  //判断store.gettes.isLogin ===false
  if(to.path == '/login'||to.path == '/register'){
    next();
  }else{
    alert("还没有登录,请先登录");
    next('/login');
  }

})*/
//后置钩子
/*router.afterEach((to,from)=>{
  alert("after each");
})*/
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

浏览器滚动行为:第一种到制定的位置

第二张到制定的标签或者id位置

第三种,到上次浏览的位置

猜你喜欢

转载自www.cnblogs.com/xiufengchen/p/10707314.html