父组件
<template>
</template>
<script>
import SelfToast from '@/T0xAC/components/common/selfToast.vue'
export default {
components: {
WxSwitch,
CurveCommon,
mideaHeader,
SelfToast
},
data() {
return {
trigger:false,
};
},
created() {
globalEvent.addEventListener('receiveMessage', (data) => {
});
},
mounted() {
setTimeout(() => {
this.trigger=true
}, 1000)
},
methods: {
};
<script>
子组件
<template>
<div class="overlay" v-if="toast">
<text class="textStyle">{{showMsg}}</text>
</div>
</template>
<script>
export default {
name: "self-toast",
props: {
showMsg:{
type: String,
default: "默认"
},
trigger:{
type: Boolean,
// default: ""
}
},
data: () => ({
toast:false,
timeOut:0
}),
watch: {
trigger:function(news,olds) {
if (news != olds) {
this.toast = true;
// this.showMsg='设定风速已是最小限制';
clearTimeout(this.timeOut);
this.timeOut = setTimeout(()=>{
this.toast=false;
},1200)
}
}
}
}
</script>
<style scoped>
.overlay {
width: 750px;
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
text-align: center;
justify-content: center;
align-items: center;
}
.textStyle {
background-color: #000000;
padding-top: 26px;
padding-left: 64px;
padding-right: 64px;
padding-bottom: 26px;
color:rgba(255,255,255,0.8);
font-size: 28px;
}
</style>