<template>
<div class="toast" ref="wrapper">
<slot v-if="!enableHtml"></slot>
<div v-else v-html="$slots.default"></div>
<template v-if="closeButton">
<div class="line" ref="line"></div>
<span class="close" @click="onClickClose">{{closeButton.text}}</span>
</template>
</div>
</template>
mounted() {
//解决方法 this.$nextTick 与 getBoundingClientRect()
this.$nextTick(()=>{
this.$refs.line.style.height=`${this.$refs.wrapper.getBoundingClientRect().height}px`
})
},
执行 this.$refs.wrapper.getBoundingClientRect()
获取到
x: 681.4140625
y: 0
width: 540.171875
height: 40
top: 0
right: 1221.5859375
bottom: 40
left: 681.4140625