1. 将所要获取的元素加入ref属性
<div slot="header" class="clearfix" ref="clearFix">
</div>
2.获取元素对象,并修改样式
methods: {
changeStyle: function () {
let headerElem = this.$refs.clearFix.parentNode
headerElem.style.padding = '0px'
headerElem.style.minHeight = '0px'
headerElem.style.backgroundColor = '#008065'
},
}
3.调用
mounted() {
this.changeStyle()
},
标签:style,Vue,headerElem,样式,元素,获取,changeStyle,CSS,页面 From: https://www.cnblogs.com/wei6/p/16726580.html