npm i vuejs-alert --save
//main.js
import Alert from 'vuejs-alert';
Vue.use(Alert);
//.vue files
/*show component*/
this.$alert.show({text: 'hello world'});
/*close component*/
this.$alert.close();
use option to custom the component.
option is an object.
Use option in the following ways:
- Set option once.
this.$alert.show(option);
- Set option globally, the next time you show the component, option would still be effective.
Vue.use(Alert, option);
option available:
key | type | default | description |
---|---|---|---|
text | string | alert text | |
confirmText | string | "确定" | text of confirm button |
cancelText | string | "取消" | text of cancel button |
confirmCallback | function | function to call when confirm button is clicked | |
cancelCallback | function | function to call when cancel button is clicked | |
duration | number | auto close time, 1000 = 1 second | |
background | string | 0.5 | opacity of background color, range from 0 to 1 |
The MIT License