js添加类名移除类名

添加类名

classList.add
document.getElementById('app').classList.add("appForSearch")

移除类名

classList.remove
document.getElementById('app').classList.remove("appForSearch")

监听路由变化动态添加

    watch:{
      $route(){
        if(this.$route.path == '/Search'){
          document.getElementById('app').classList.add("appForSearch")
        }else{
          document.getElementById('app').classList.remove("appForSearch")
        }
      }
    }

 

posted @ 2022-04-20 09:23  从入门到入土  阅读(307)  评论(0编辑  收藏  举报