# vuejs-dialog
**Repository Path**: uwell/vuejs-dialog
## Basic Information
- **Project Name**: vuejs-dialog
- **Description**: 一个轻量级、基于 Promise 开发的警告、提示和确认对话框组件
- **Primary Language**: JavaScript
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2020-08-16
- **Last Updated**: 2022-05-29
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Vuejs Dialog Plugin
> A lightweight, promise based alert, prompt and confirm dialog.
[](https://badge.fury.io/js/vuejs-dialog)
[](https://travis-ci.org/Godofbrowser/vuejs-dialog)
[](https://scrutinizer-ci.com/g/Godofbrowser/vuejs-dialog/?branch=master)
[](https://github.com/Godofbrowser/vuejs-dialog/archive/master.zip)


## Demo
[https://godofbrowser.github.io/vuejs-dialog/](https://godofbrowser.github.io/vuejs-dialog/)
## Important updates in version v1.x.x
1. Dialog will always resolve with an object. (i.e callback for proceed always will receive an object)
2. For directives usage, the object returned in (1) above will include a node. The node is the element the directive was bound to (see issue [#5](https://github.com/Godofbrowser/vuejs-dialog/issues/5)
3. Styles will have to be included explicitly as they have been extracted into a separate file (see issue [#28](https://github.com/Godofbrowser/vuejs-dialog/issues/28))
4. If loader is enabled globally, and a dialog is triggered via a directive without a callback, the loader is ignored for clicks on proceed
5. Custom class injection on parent node (see issue [#25](https://github.com/Godofbrowser/vuejs-dialog/issues/25))
6. Ability to register custom views. This allows for custom logic, custom buttons, etc (see issue [#13](https://github.com/Godofbrowser/vuejs-dialog/issues/13), [#14](https://github.com/Godofbrowser/vuejs-dialog/issues/14), [#33](https://github.com/Godofbrowser/vuejs-dialog/issues/33))
7. For installation via **HTML script tag**
- The library has been namespaced as it has been split into two. The main library which is the plugin and the mixin which is useful in custom components
- To this effect, the new way to install the plugin is slightly dufferent: `window.Vue.use(VuejsDialog.main.default)`
- And the mixin can be added to components like so: `mixins: [VuejsDialog.mixin.default, ...otherMixins]`
## Installation
#### HTML
```html
// Include vuejs
// Include vuejs-dialog plugin
// only needed in custom components
```
#### Package Manager
```javascript
// installation via npm
npm i -S vuejs-dialog
// or
// installation via yarn
yarn add vuejs-dialog
```
```javascript
// then
// import into project
import Vue from 'vue';
import VuejsDialog from 'vuejs-dialog';
import VuejsDialogMixin from 'vuejs-dialog/dist/vuejs-dialog-mixin.min.js'; // only needed in custom components
// include the default style
import 'vuejs-dialog/dist/vuejs-dialog.min.css';
// Tell Vue to install the plugin.
Vue.use(VuejsDialog);
```
#### Webpack External
```javascript
// If you're including via script tag and importing as Webpack external
// Webpack config
{
// ... other webpack config
externals: {
// .. other externals if any
'vuejs-dialog': 'VuejsDialog'
}
}
```
```javascript
// then
// import into project
import Vue from 'vue';
import VuejsDialog from 'vuejs-dialog';
// Tell Vue to install the plugin.
Vue.use(VuejsDialog.main.default);
// mixin available at: VuejsDialog.mixin.default
```
## Basic Usage inside a vuejs application
```javascript
// Anywhere in your Vuejs App.
// Trigger an Alert dialog
this.$dialog.alert('Request completed!').then(function(dialog) {
console.log('Closed');
});
// Trigger a confirmation dialog
this.$dialog
.confirm('Please confirm to continue')
.then(function(dialog) {
console.log('Clicked on proceed');
})
.catch(function() {
console.log('Clicked on cancel');
});
```
## Basic Usage outside a vuejs application
```javascript
// VuejsDialog Methods are also available on the global vue
// This makes it possible to use the plugin inside a ReactJs application
// or just any javascript application
// Simply include vue, vuejs-dialog, ask vue to use the plugin and that's all:
Vue.dialog.alert('Request completed!').then(function(dialog) {
console.log('Closed');
});
Vue.dialog
.confirm('Please confirm to continue')
.then(function(dialog) {
console.log('Clicked on proceed');
})
.catch(function() {
console.log('Clicked on cancel');
});
```
## Return value on success
```javascript
// Whenever a user clicks on proceed,
// the promise returned by the dialog call will be
// resolved with a dialog object with the following shape:
{
close: function | sometimes | A method that can be used to close the dialog if it's in a loading state
loading: function | sometimes | A method that can be used to stop the dialog loader
node: DOMElement | sometimes | A DOM element which the directive was bound to, when triggered via a directive
data: any | always | Data sent with the positive action. Useful in prompts or custom components where you have multiple proceed buttons
}
// Example: