vue页面重置和刷新(vue数据重置)

一、this.reload()方法(体验度好,无空白页面,相当于页面数据重置)

1、在app.vue文件中配置:


import _ from 'lodash'//引入
 //自定义
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
  //定义状态
      isRouterAlive: true,
    }
  },
  methods: {
    //重置方法
    reload() {
      this.isRouterAlive = false
      this.$nextTick(() => {
        this.isRouterAlive = true
      })
    }
  }

2、在需要使用的页面中引入参数使用:

//需要使用的页面引入
export default {
inject: ['reload'], 
methods: {
    //事件方法
    getReload() {
      this.reload() //重置刷新
    },
  }
}

二、利用vue中的路由方法(偏向于刷新页面)

this.$router.go(0)

三、利用window的reload方法(强制刷新)

window.location.reload()



 

你可能感兴趣的:(vue,vue.js,vscode,vue.js,前端)