index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Vue from 'vue';
  2. import DispatchMaster from './DispatchMaster'; // 引入组件
  3. const DispatchMasterController = Vue.extend(DispatchMaster); // 发送班主任分班
  4. let instance;
  5. function initInstance(type) {
  6. switch (type) {
  7. case 'Test':
  8. instance = new DispatchMasterController({
  9. el: document.createElement('div'),
  10. })
  11. break
  12. }
  13. // 标识已被挂载过一次
  14. instance.constrctType = type
  15. }
  16. // 导出一个方法,接受配置参数
  17. export default (type,options,callback) => {
  18. if (!instance || instance.constrctType !== type) {
  19. // 未被挂载
  20. console.log('挂载')
  21. initInstance(type); // 挂载
  22. }
  23. Object.assign(instance, options);
  24. // 实例化后newInstance就是一个对象了,所以data内的数据会
  25. // 挂载到this下,传入一个对象与之合并
  26. instance.show = true
  27. if(instance.init) {
  28. instance.init()
  29. }
  30. instance.success = (data) => {
  31. callback(data)
  32. }
  33. document.body.appendChild(instance.$el)
  34. // return instance.show(vm => {
  35. // instance = null; // 将实例对象清空
  36. // })
  37. }