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();

}

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