index.js 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // bottom:true
  12. }
  13. : optios;
  14. // 插入到app组件下
  15. const getParent = () => c?.$vuetify?.app ?? window?.$nuxt;
  16. const toast = (optios) => {
  17. optios = fixOptios(optios);
  18. return new Toast({
  19. parent: getParent(),
  20. propsData: {
  21. // message: optios.message,
  22. // icon: optios.icon,
  23. ...optios,
  24. },
  25. }).$mount();
  26. };
  27. ['error', 'success', 'warning', 'info'].forEach((key) => {
  28. toast[key] = (optios) => {
  29. optios = fixOptios(optios);
  30. return toast({
  31. ...optios,
  32. icon: '$' + key,
  33. });
  34. };
  35. });
  36. i('toast', toast);
  37. }