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