在vue.app里创建一个mounted生命函数,在methods里写入一个方法:
mounted(){
this.beforeCreate()
},
methods:{
beforeCreate () { // 浏览器刷新之后回到登录页面
if (this.$router.path !== '/') {
this.$router.replace('/about')
}
}
}
该博客介绍了如何在Vue.js应用程序中使用`mounted`生命周期钩子来调用一个方法。这个`beforeCreate`方法会在页面刷新后检查当前路由,如果路径不是'/about',则会将用户重定向到登录页面,确保了用户在刷新后始终从登录页面开始。
在vue.app里创建一个mounted生命函数,在methods里写入一个方法:
mounted(){
this.beforeCreate()
},
methods:{
beforeCreate () { // 浏览器刷新之后回到登录页面
if (this.$router.path !== '/') {
this.$router.replace('/about')
}
}
}
3029

被折叠的 条评论
为什么被折叠?