vue在刷新页面后如何保证路由不变

1247 ℃

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')
    }
  }
}

Motion for Vue:一个轻量级且功能强大的Vue3动画库

el-table合并行的通用方法(附js代码)

vue前端分页功能实现代码(附js代码)

el-table利用:row-style="rowClass"设置指定行变色

一款免费开源效果酷炫​的 Vue / React 大屏数据展示组件库——DataV 

标签: vue刷新页面, vue获取路由, 监听beforeunload事件

上面是“vue在刷新页面后如何保证路由不变”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_4730.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

生活小工具

收录了万年历、老黄历、八字智能排盘等100+款小工具!生活小工具
vuejs通过input实现表格/列表模糊搜索代码分析
js如何把字符串分割并转成数组
如何安装从各种源码网上下载的织梦源码
帝国cms功能之充值类型管理介绍教程
wordpress如何删除版本号