vue body to set a different background color in different pages

1. ideas, css do not go this route, trying to solve problems with coverage. To pass the life cycle, js logic.

Assembly through a "Initialization" and "destruction", to control the body color, a very simple logic

The following is a specific code.

<script>
beforeCreate: function() {
   document.getElementsByTagName("body")[0].className="body_back";
},
beforeDestroy: function() {
  document.body.removeAttribute("class","body_back");
}
</script>

<style>
.body_back
  background linear-gradient(#0a0675, #0b30b3) // 这是线性渐变
</style>

 

Guess you like

Origin www.cnblogs.com/tengyuxin/p/11207432.html