解决Vue中watch首次进入路由不触发的问题

//原本写法
watch: {
         '$route.path': function (newVal, oldVal) {
             if (newVal === '/HomePageData') {
                 this.isBgc = true;
             } else {
                this.isBgc = false;
            }
         },
    }
// 修改写法
watch: {
        '$route.path': {
            immediate: true,
            handler(newVal, oldVal) {
                if (newVal === '/HomePageData') {
                    this.isBgc = true;
                } else {
                    this.isBgc = false;
                }
            }
        }
    }
原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/13801927.html