// 默认选项
const DefaultOptions = {
duration: 1500,
type: info ,
content: 这是一条提示信息!,
}
let mid = 0
export default {
data() {
return {
notices: []
}
},
methods: {
add(notice = {}) {
// name标识 用于移除弹窗
let _name = this.getName()
// 合并选项
notice = Object.assign({
_name
}, DefaultOptions, notice)
this.notices.push(notice)
setTimeout(() => {
this.removeNotice(_name)
}, notice.duration)
},
getName() {
return msg_ + (mid++)
},
removeNotice(_name) {
let index = this.notices.findIndex(item => item._name === _name)
this.notices.splice(index, 1)
}
}
}