<template>
<div
class="app-toast"
v-if="isShow"
:class="{
info: type === 'info',
success: type === 'success',
wraning: type === 'wraning',
danger: type === 'danger'
}"
>
{{ text }}
</div>
</template>
<style scoped>
.app-toast {
position: fixed;
left: 50%;
top: 5%;
background: #ccc;
padding: 10px;
border-radius: 5px;
transform: translate(-50%, -50%);
color: #fff;
}
.info {
background: #00aaee;
}
.success {
background: #00ee6b;
}
.wraning {
background: #eea300;
}
.danger {
background: #ee000c;
}
</style>
import vue from "vue";
import toastComponent from "@/components/VNotify.vue";
const ToastConstructor = vue.extend(toastComponent);
function showToast({ text, type, duration = 3000 }) {
const toastDom = new ToastConstructor({
el: document.createElement("div"),
data() {
return {
isShow: true,
text: text,
type: type
};
}
});
document.body.appendChild(toastDom.$el);
setTimeout(() => {
toastDom.isShow = false;
}, duration);
}
function registryToast() {
vue.prototype.$toast = showToast;
}
export default registryToast;
import toastRegistry from "./uitls/ntify";
Vue.use(toastRegistry);