UNPKG

ship-view-ui-plus

Version:

A high quality UI components Library with Vue.js 3

45 lines (38 loc) 1.21 kB
import Notification from './notification.vue'; import { createApp, h, getCurrentInstance } from 'vue'; import { isClient } from '../../../utils/index'; Notification.newInstance = properties => { if (!isClient) return; const _props = properties || {}; let _instance = null; const Instance = createApp({ render () { return h(Notification, Object.assign({ ref: 'notification' }, _props)); }, created () { _instance = getCurrentInstance(); } }); const container = document.createElement('div'); document.body.appendChild(container); Instance.mount(container); const notification = _instance.refs.notification; return { notice (noticeProps) { notification.add(noticeProps); }, remove (name) { notification.close(name); }, component: notification, destroy (element) { notification.closeAll(); isClient && setTimeout(function() { document.body.removeChild(document.getElementsByClassName(element)[0]); }, 500); } }; }; export default Notification;