vant/packages/dialog/index.js
neverland 7a3fef0a09
[bugfix] Dialog should reset button text when showed (#278)
* [bugfix] CouponList always show empty info

* [bugfix] add click feedback of buttons in components

* [Doc] add custom theme document

* [new feature] Notice bar support more props

* [bugfix] PullRefresh test cases

* [bugfix] unused NoticeBar style

* [bugfix] Swipe width calc error

* [Doc] english document of all action components

* [Doc] change document site path to /zanui/vant

* [Doc] fix

* [bugfix] uploader style error

* [bugfix] tabs document demo

* [new feature] Cell support vue-router target route

* [bugfix] add cell test cases

* update yarn.lock

* [bugfix] Tabbar cann't display info when use icon slot

* [Doc] update document title

* [bugfix] Dialog should reset button text when showed

* [new feature] CouponList add showCloseButton prop
2017-11-02 05:00:29 -05:00

65 lines
1.1 KiB
JavaScript

import Vue from 'vue';
import DialogComponent from './dialog';
let instance;
const defaultConfig = {
value: true,
title: '',
message: '',
confirmButtonText: '确认',
cancelButtonText: '取消',
showCancelButton: false,
closeOnClickOverlay: false,
callback: action => {
instance[action === 'confirm' ? 'resolve' : 'reject'](action);
}
};
const initInstance = () => {
const DialogConstructor = Vue.extend(DialogComponent);
instance = new DialogConstructor({
el: document.createElement('div')
});
instance.$on('input', value => {
instance.value = value;
});
document.body.appendChild(instance.$el);
};
const Dialog = options => {
return new Promise((resolve, reject) => {
if (!instance) {
initInstance();
}
Object.assign(instance, {
resolve,
reject,
...options
});
});
};
Dialog.alert = options => Dialog({
...defaultConfig,
...options
});
Dialog.confirm = options => Dialog({
...defaultConfig,
showCancelButton: true,
...options
});
Dialog.close = () => {
instance.value = false;
};
export default Dialog;
export {
DialogComponent as Dialog
};