vue 路由参数变化,页面数据不更新 解决方法

路由参数改变:
http://localhost:8080/?#/PerformanceReview?pid=157811552224000029
http://localhost:8080/?#/PerformanceReview?pid=157803611191800025
参数切换后,页面没刷新,数据没更新

解决方法:
监听路由变化,若参数改变,则重新加载数据,刷新页面

watch: {
        '$route' (to, from) {   //监听路由是否变化
            if(to.query.pid != from.query.pid && to.query.pid != null){  //pid不为空才请求数据
                this.pid = to.query.pid;
                this.getData(); //调接口,请求数据
            }
        }
    },
    created() {
        if(this.$route.query.pid === null || this.$route.query.pid === undefined) {  //如pid为空,则不请求数据
            this.$message.error('无指定的项目数据');
            return
        }
        else{ //否则请求数据
            this.pid = this.$route.query.pid;
            this.getData();
        }
    },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。