import Confirm from './main.vue' import Vue from 'vue' let ConfirmConstructor = Vue.extend(Confirm) let instance let seed = 1 let index = 1000 const install = () => { Object.defineProperty(Vue.prototype, '$confirm', { get () { let id = 'message_' + seed++ const confirmMsg = options => { instance = new ConfirmConstructor({ propsData: options }) index++ instance.id = id instance.vm = instance.$mount() document.body.appendChild(instance.vm.$el) instance.vm.$el.style.zIndex = index return instance.vm } return confirmMsg } }) } export default install
vue组件挂载到全局方法的示例代码(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/52dd103bc2066f920bea39b5ea327b29.html