index.js 894 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { createApp } from 'vue'
  2. import confirm from './confirm.vue'
  3. import vuetify from '@/plugins/vuetify'
  4. const toastMessage = (title, text, option = {}) => {
  5. return new Promise((resolve, reject) => {
  6. const rootNode = document.createElement("div")
  7. document.querySelector('.v-application').appendChild(rootNode)
  8. const app = createApp(confirm, {
  9. title,
  10. text,
  11. cancel () {
  12. app.unmount()
  13. rootNode.remove()
  14. if (option.cancelCallback) {
  15. reject()
  16. }
  17. },
  18. sure () {
  19. app.unmount()
  20. rootNode.remove()
  21. resolve()
  22. }
  23. })
  24. app.use(vuetify)
  25. app.mount(rootNode)
  26. })
  27. }
  28. // 注册插件app.use()会自动执行install函数
  29. toastMessage.install = (app) => {
  30. app.config.globalProperties.Confirm = toastMessage
  31. }
  32. export default toastMessage