vue-cli爲頁面設置body背景顏色

1.直接在當前的page內設置如下:

beforeCreate () {

  document.querySelector('body').setAttribute('style', 'background-color:#fff')

},

beforeDestroy () {

  document.querySelector('body').removeAttribute('style')

}

 

2.在全局路由鉤子那邊添加判斷:

if (to.meta.name == "release") // 這個爲自己添加的meta內容

   document.querySelector("body").setAttribute("style","background-color: #fff")

   next();

}else {

   document.querySelector("body").setAttribute("style","background-color: #EEEEEE")

   next();

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章