Vue修改组件背景颜色


 

 

由于组件内样式是私有化的,在组件内直接设置样式会不生效,

如果想改变组件的默认背景色,可通过beforeCreate (),beforeDestroy ()

代码如下:

// 创建节点之前设置背景色
 beforeCreate() { document.querySelector('body').setAttribute('style', 'background:#fafafa') document.querySelector('html').setAttribute('style', 'background:#fafafa') }, // 销毁节点之前删除属性
 beforeDestroy() { document.querySelector('body').removeAttribute('style') document.querySelector('html').removeAttribute('style') }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM