首先写好一个组件
然后将他转为vue实例,并且暴露实例
import Vue from 'vue' import Component from './index.vue' const Loading = Vue.extend(Component) const instance = new Loading({ el: document.createElement('div') }) instance.show = () => { instance.value = true document.body.appendChild(instance.$el) } instance.hide = () => { document.body.removeChild(instance.$el) } export default instance
如果需要全局注册,暴露install方法即可