diff --git a/docs/notification.md b/docs/notification.md index 2aaaa6e..cff2d32 100644 --- a/docs/notification.md +++ b/docs/notification.md @@ -28,6 +28,6 @@ import { Notification } from 'vue-desktop' - title: Notification 显示的标题。 - message: Notification 显示的内容。 -- type: Notification 显示的图标的类型,可选值:success、info、warning、error,默认值为info。 -- duration: Notification 显示的时长,单位为秒,默认值为5。 +- type: Notification 显示的图标的类型,可选值:success、info、warning、error,默认值为 info。 +- duration: Notification 显示的时长,单位为秒,默认值为 5。设置为 0 则会一直显示,直到用户手动关闭。 - callback: Notification 关闭后的回调函数,参数 instance 为对应于该 Notification 的 Vue 实例对象,它具有上述四个属性,instance.id 为唯一性标识。 \ No newline at end of file diff --git a/examples/service/notification.vue b/examples/service/notification.vue index ebeefad..4f0bfec 100644 --- a/examples/service/notification.vue +++ b/examples/service/notification.vue @@ -27,7 +27,7 @@ title: '通知', message: '通知信息', type: 'warning', - duration: 2 + duration: 0 }); }, notification4() { diff --git a/src/service/notification.vue b/src/service/notification.vue index 010ddd5..cac6963 100644 --- a/src/service/notification.vue +++ b/src/service/notification.vue @@ -138,21 +138,25 @@ startTimer() { var self = this; + if (this.duration > 0) { + this.timer = setTimeout(function() { + if (!self.closed) { + self.handleClose(); + } + }, this.duration * 1000); + } + } + }, + + ready() { + var self = this; + if (this.duration > 0) { this.timer = setTimeout(function() { if (!self.closed) { self.handleClose(); } }, this.duration * 1000); } - }, - - ready() { - var self = this; - this.timer = setTimeout(function() { - if (!self.closed) { - self.handleClose(); - } - }, this.duration * 1000); } } \ No newline at end of file