美文网首页
Vue this.route.push跳转页面不刷新

Vue this.route.push跳转页面不刷新

作者: 风赼 | 来源:发表于2020-03-28 14:13 被阅读0次

    使用this.route.push跳转页面时数据没有刷新,我在网上查找到了几种方法:

    1、使用activated():{}周期函数代替mounted():{}

    当组件在 <keep-alive> 内被切换,它的 activated 和 deactivated 这两个生命周期钩子函数将会被对应执行。

    将请求数据的函数写在 activated():{},每次进入页面就能获取到最新数据。

    activated ():{

        //this.getData()

    }

    2、watch监听路由,请求数据

    watch: {

        '$route' (to, from) {

        //请求数据

        }

    但是使用这个方法会请求两次数据。

    3、watch监听路由,强制刷新

    watch: {

        '$route'(to,from) {

            this.$router.go(0);

        }

    }

    使用该方法会导致页面有一段很长的白屏时间,用户体验感不好。

    相关文章

      网友评论

          本文标题:Vue this.route.push跳转页面不刷新

          本文链接:https://www.haomeiwen.com/subject/pwgjuhtx.html