組件默認背景顏色為白色,但工作需要改成黑色,於是研究了一番。
很簡單,只需在組件中使用兩個鈎子函數beforeCreate (),beforeDestroy ()
代碼如下:
beforeCreate () { document.querySelector('body').setAttribute('style', 'background:#000000') }, beforeDestroy () { document.querySelector('body').removeAttribute('style') }
在創建之前,添加body的style屬性,將背景顏色設置為黑色
在銷毀前,將body的style屬性刪除。