-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (32 loc) · 977 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var ToastTpl = require('./toast.vue').default; // loader 默认启用 esModule 因此要加default
var Toast = {}
Toast.install = (Vue, opts) => {
if (document.getElementsByClassName('alertBox').length) {
return
}
let tpl = Vue.extend(ToastTpl)
let $vm = new tpl()
let mountedTpl = $vm.$mount().$el
document.body.appendChild(mountedTpl)
Vue.prototype.$toast = {
show(opts) {
if (typeof opts === 'string') {
$vm.text = opts
}
if (typeof opts === 'object') {
Object.assign($vm, opts)
}
$vm.toggleIt({show:true},(e)=> {
if (e) {
typeof opts.success == 'function'&& opts.success(e)
} else {
typeof opts.error == 'function'&& opts.error(e)
}
})
},
hide() {
$vm.toggleIt(false)
}
}
}
export default Toast