-
- {this.genIcon()}
- {this.genMessage()}
-
-
+ {this.genIcon()}
+ {this.genMessage()}
+
);
},
});
diff --git a/src/toast/index.js b/src/toast/index.js
index c3ec0ec12..cc9c0b49a 100644
--- a/src/toast/index.js
+++ b/src/toast/index.js
@@ -1,14 +1,10 @@
-import Vue from 'vue';
-import VueToast from './Toast';
-import { isObject, isServer } from '../utils';
-import { removeNode } from '../utils/dom/node';
+import { createApp, nextTick } from 'vue';
+import VanToast from './Toast';
+import { isObject, inBrowser } from '../utils';
const defaultOptions = {
icon: '',
type: 'text',
- // @deprecated
- mask: false,
- value: true,
message: '',
className: '',
overlay: false,
@@ -45,18 +41,69 @@ function parseOptions(message) {
function createInstance() {
/* istanbul ignore if */
- if (isServer) {
+ if (!inBrowser) {
return {};
}
if (!queue.length || multiple) {
- const toast = new (Vue.extend(VueToast))({
- el: document.createElement('div'),
+ const root = document.createElement('div');
+ document.body.appendChild(root);
+
+ const app = createApp({
+ data() {
+ return {
+ timer: null,
+ toastProps: {
+ show: false,
+ },
+ };
+ },
+ methods: {
+ clear() {
+ this.toggle(false);
+ },
+ toggle(show, duration) {
+ this.toastProps.show = show;
+
+ if (show) {
+ clearTimeout(this.timer);
+
+ if (duration > 0) {
+ this.timer = setTimeout(() => {
+ this.clear();
+ }, duration);
+ }
+ }
+ },
+ setProps(props) {
+ this.toastProps = {
+ ...props,
+ duration: undefined,
+ };
+ },
+ onClosed() {
+ if (multiple && inBrowser) {
+ clearTimeout(this.timer);
+ queue = queue.filter((item) => item !== this);
+ app.unmount();
+ document.body.removeChild(root);
+ }
+ },
+ },
+ render() {
+ return (
+