效果

代码
Vue.prototype.$notice = (arg) => {
createwomo(Noticewomo, arg)
}
import Vue from 'vue'
export function createwomo (component, props) {
const vm = new Vue({
render: (h) => {
return h(component, { props })
}
})
vm.$mount()
document.body.appendChild(vm.$el)
const comp = vm.$children[0]
comp.remove = () => {
document.body.removeChild(vm.$el)
vm.$destroy()
}
}
<template>
<div class="box" v-if="isShow">
<h3>{{ title }}</h3>
<p class="box-content">{{ message }}</p>
</div>
</template>
<script>
export default {
data(){
return {
isShow: false
}
},
props: {
title: {
type: String,
default: ''
},
message: {
type: String,
default: ''
},
duration: {
type: Number,
default: 1000,
}
},
mounted(){
this.show()
},
methods: {
show() {
this.isShow = true
setTimeout(this.hide, this.duration)
},
hide() {
this.isShow = false
this.remove()
}
}
}
</script>
<style>
.box {
position: fixed;
width: 40%;
top: 10px;
left: 50%;
transform: translate(-50%);
text-align: center;
pointer-events: none;
border-color: #fff;
border: gray 3px solid;
box-sizing: border-box;
}
.box-content {
width: 200px;
margin: 10px auto;
font-size: 14px;
padding: 8px 16px;
background: #fff;
border-radius: 3px;
margin-bottom: 8px;
}
</style>