
vue开发中,如何在刷新页面后保证路由不会变化,下面web建站小编给大家简单介绍一下!
具体代码如下:
export default {
created() {
// 监听beforeunload事件
window.addEventListener("beforeunload", this.saveCurrentPath)
},
beforeDestroy() {
// 解除beforeunload事件的绑定
window.removeEventListener('beforeunload', this.saveCurrentPath)
},
methods: {
saveCurrentPath() {
//当前路由的路径保存到localStorage
localStorage.setItem('currentRoutePath', this.$route.path)
}
},
mounted() {
const currentRoutePath = localStorage.getItem('currentRoutePath')
if (currentRoutePath) {
this.$router.push(currentRoutePath)
//执行后清除localStorage缓存
localStorage.removeItem('currentRoutePath')
}
}
}
element-ui时间选择器el-date-picker默认当前时间至7天之前时间
vue实现表格的编辑,包括选择,合并,拆分,删除行/列,添加行/列
Motion for Vue:一个轻量级且功能强大的Vue3动画库
标签: vue刷新页面, vue获取路由, 监听beforeunload事件
上面是“vue在刷新页面后如何保证路由不变”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4730.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

vuejs项目中如何禁止eslint检测
积木大师俱乐部:中国注册的权威性积木组织
Fansly Downloader:专为Fansly平台打造的高效便捷的内容下载工具