<template>
<div class="msg" ref="msg" :class="{ active: msgStatus }">
<div>
{{ text }}
</div>
</div>
</template>
<script>
export default {
// el-button el-form
name: "vue-msg",
data() {
return {
msgStatus: false,
text: "",
};
},
methods: {
// 以默认配置为优先(容错)
// 以用户配置为覆盖(扩展性)
msgPlugin(msg, time = 2000) {
this.text = msg;
this.msgStatus = true;
setTimeout(() => {
this.msgStatus = false;
}, time);
}
}
};
</script>
<style scoped>
.msg {
position: absolute;
left: 50%;
top: 30%;
transform: translate(-50%, -50%);
width: 0;
min-height: 0;
text-align: center;
background: rgba(0, 0, 0, 0.5);
border-radius: 5px;
color: #ffffff;
transition: all 0.5s;
z-index: -1;
opacity: 0;
}
.msg.active {
width: 150px;
min-height: 25px;
opacity: 1;
z-index: 11;
}
</style>
06-24
12-08