想设置某一页的背景图片,其他页不受影响。起初,我在style中设置
<style>
body{
background-image: url("../assets/bg5.jpg");
background-size: cover;
background-repeat: no-repeat;
}
</style>
但会使其他页面被影响,导致所有页面都有这个背景图片。
解决方法:
mounted() {
document.querySelector('body').setAttribute('style', "background-image: url("+require("../assets/bg5.jpg")+");background-size: cover;" +
"background-repeat: no-repeat")
},
beforeDestroy() {
document.querySelector('body').removeAttribute('style')
},
这样,当打开此页面时,显示它的背景图片,离开页面后,背景销毁。