From 617e594466b3d76bf4c1e144dc448ce61fbec083 Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Thu, 12 May 2016 11:57:09 +0800 Subject: [PATCH] =?UTF-8?q?notification=20=E5=8F=AF=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E4=B8=8D=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/notification.md | 4 ++-- examples/service/notification.vue | 2 +- src/service/notification.vue | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) 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