UNPKG

@58fe/p5

Version:

pc端vue组件

48 lines (42 loc) 842 B
import Vue from 'vue'; import Dialog from './../../components/dialog'; const plugin = { install(vue, props = {}) { const DialogPlugin = Vue.extend(Dialog); let $vm = new DialogPlugin({ el: document.createElement('div') }); document.body.appendChild($vm.$el); function dialog(options = {}) { if ($vm.show) { return; } $vm = Object.assign($vm, props, options); $vm.show = true; return new Promise((resolve, reject) => { $vm.$on('cancel', val => { resolve('cancel'); }); $vm.$on('ok', val => { resolve('ok'); }); $vm.$on('close', val => { resolve('close'); }); }); } if (!vue.$p5) { vue.$p5 = { dialog }; } else { vue.$p5.dialog = dialog; } vue.mixin({ created: function() { this.$p5 = vue.$p5; } }); } }; export default plugin;