Vue 不同路由对应同一页面 监测路由变化更改数据 阿星小栈

   watch: {
        orgTreeShow(val){
            if(val){
                this.employeesShow = false;
            }else{
                this.loadEmployees()
            }
        }
    },
    beforeUpdate: function(){
        console.log('beforethis.$route',this.$route);
        if(this.$route.fullPath === '/company-manage/dept-frame' || this.$route.fullPath === '/theatre-manage/dept-frame'){
            this.orgTreeShow = true
        }else{
            this.orgTreeShow = false;
        }
    },
    created () {
        console.log('this.$route',this.$route);
        this.orgTreeShow = false;
        if(this.$route.fullPath === '/company-manage/dept-frame' || this.$route.fullPath === '/theatre-manage/dept-frame'){
            this.orgTreeShow = true
        }
        if(this.orgTreeShow){
            this.loadDeptsTree()
        }else{
            this.loadEmployees()
        }
    },
原文地址:https://www.cnblogs.com/dereckbu/p/8483952.html