Vue

vue设置body背景色

2019-03-18  本文已影响0人  左木北鱼

1. 问题:

开发过程中,可能不同路由页面背景色不一样,可以通过js来设置。

2. 解决:

  1. 直接在当前的page内设置
mounted() {
  document.querySelector('body').setAttribute('style', 'background-color:#f7f7f7')
},
beforeDestroy() {
  document.querySelector('body').removeAttribute('style')
}
  1. 在全局路由钩子添加
  // 设置背景色
  if (to.meta.background === 'gray') {
    document.querySelector('body').setAttribute('style', 'background: #f7f7f7')
  } else {
    document.querySelector('body').setAttribute('style', 'background: #fffff')
  }
上一篇 下一篇

猜你喜欢

热点阅读