html里面是可以在body上面添加class样式来达到自己想要的效果,但是如果改成vue的单页面应用,就没有body这个属性了,那需要怎么才能把样式加上呢,肯定不能直接在template标签上加吧,比如

<html>
	<body class ="grayColor">
	</body>
</html>

这样的页面样式转换到vue中需要怎么动呢,有遇到这种情况想了个临时解决办法

  mounted () {
    document.getElementsByTagName('body')[0].className = 'grayColor'
  },
  destroyed () {
    document.body.removeAttribute('class')
  }

即在页面加载完成的时候把样式加上,在销毁的时候把属性移除,可以达到想要的效果,有小伙伴有更好的解决方法的话,可以分享下哈

Logo

前往低代码交流专区

更多推荐