vue中在个别组件中给body添加类名
首先我给body加类名是更改element-ui中下拉框的背景色,beforeCreate() {document.getElementsByTagName("body")[0].className="equipment-body";},beforeDestroy(){document.body.removeAttribute("class","equipment-...
·
首先我给body加类名是更改element-ui中下拉框的背景色,
beforeCreate() {
document.getElementsByTagName("body")[0].className="equipment-body";
},
beforeDestroy(){
document.body.removeAttribute("class","equipment-body");
},
开始的时候我按照上面这种方法写,但是有点小问题,就是有时候进入组件的时候类名没有加上,后来我更改了写法,把
document.getElementsByTagName("body")[0].className="equipment-body";写到mounted中,然后beforeDestroy不变,如下
mounted(){
document.getElementsByTagName("body")[0].className="equipment-body";
}
beforeDestroy(){
document.body.removeAttribute("class","equipment-body");
},
这样写效果就可以了。
更多推荐
已为社区贡献20条内容
所有评论(0)