toast/
--index.js
--Toast.vue
import Toast from './Toast';
const obj = {};
obj.install = function (Vue) {
// 创建组件构造器
const ToastConstructor = Vue.extend(Toast);
// new的方式创建组件对象
const toast = new ToastConstructor();
// 将组件对象挂载到某个元素上
toast.$mount(document.createElement('div'));
document.body.appendChild(toast.$el);
Vue.prototype.$toast = toast;
};
export default obj;
main.js中引入
import Toast from '@/components/toast';
Vue.use(Toast);