早上摸鱼懒得说话了,就这个办法,别乱找了兄弟们
话不多说上代码
<template>
<div class="box" ref="box">
</div>
</template>
<script>
export default {
name:"",
data(){
return :{
boxWidth:""
},
mounted(){
this.getDivBox()
}
},
methods:{
getDivRefs(){
//如果你想获取一个组件的节点 this.$refs.box.$el(记住是vue组件就是<helloworld ref="box" />)
this.boxWidth=this.$refs.box.style.width
console.log(this.boxWidth)
}
},
}
</script>
<style>
.box{
width:200px;
height:200px;
background-color:red;
}
</style>
这就是ref获取节点的方法,实战中非常好用,记得点赞关注哦