index.js 915 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Vue from 'vue';
  2. import toastOptions from './toast.vue';
  3. const Toast = Vue.extend(toastOptions);
  4. export default function (c, i) {
  5. const isString = (v) =>
  6. Object.prototype.toString.call(v) === '[object String]';
  7. const fixOptios = (optios) =>
  8. isString(optios)
  9. ? {
  10. message: optios,
  11. }
  12. : optios;
  13. // 插入到app组件下
  14. const getParent = () => c?.$vuetify?.app ?? window?.$nuxt;
  15. const toast = (optios) => {
  16. optios = fixOptios(optios);
  17. return new Toast({
  18. parent: getParent(),
  19. propsData: {
  20. // message: optios.message,
  21. // icon: optios.icon,
  22. ...optios,
  23. },
  24. }).$mount();
  25. };
  26. ['error', 'success', 'warning', 'info'].forEach((key) => {
  27. toast[key] = (optios) => {
  28. optios = fixOptios(optios);
  29. return toast({
  30. ...optios,
  31. icon: '$' + key,
  32. });
  33. };
  34. });
  35. i('toast', toast);
  36. }