12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import Vue from 'vue';
- import DispatchMaster from './DispatchMaster'; // 引入组件
- const DispatchMasterController = Vue.extend(DispatchMaster); // 发送班主任分班
- let instance;
- function initInstance(type) {
- switch (type) {
- case 'Test':
- instance = new DispatchMasterController({
- el: document.createElement('div'),
- })
- break
- }
- // 标识已被挂载过一次
- instance.constrctType = type
- }
- // 导出一个方法,接受配置参数
- export default (type,options,callback) => {
- if (!instance || instance.constrctType !== type) {
- // 未被挂载
- console.log('挂载')
- initInstance(type); // 挂载
- }
- Object.assign(instance, options);
- // 实例化后newInstance就是一个对象了,所以data内的数据会
- // 挂载到this下,传入一个对象与之合并
- instance.show = true
- if(instance.init) {
- instance.init()
- }
- instance.success = (data) => {
- callback(data)
- }
- document.body.appendChild(instance.$el)
- // return instance.show(vm => {
- // instance = null; // 将实例对象清空
- // })
- }
|