创建显示消息的通知,并且能自动淡出。类似Android中的Toast。

代码演示

基本形式

通知 notify - 图1

  1. <button class="u-btn u-btn-primary" on-click={this.show()}>Notify</button>
  1. var component = new NEKUI.Component({
    template: template,
    show: function() {
    NEKUI.Notify.show('This is a message.');
    }
    });

状态扩展

通知 notify - 图2

  1. <button class="u-btn u-btn-info" on-click={this.show('info')}>Info</button>
    <button class="u-btn u-btn-success" on-click={this.show('success')}>Success</button>
    <button class="u-btn u-btn-warning" on-click={this.show('warning')}>Warning</button>
    <button class="u-btn u-btn-error" on-click={this.show('error')}>Error</button>
  1. var component = new NEKUI.Component({
    template: template,
    show: function(state) {
    NEKUI.Notify[state](state + ' message.', state);
    }
    });

位置扩展

通知 notify - 图3

  1. <button class="u-btn" on-click={this.show(0)}>Top Center</button>
    <button class="u-btn" on-click={this.show(1)}>Top Left</button>
    <button class="u-btn" on-click={this.show(2)}>Top Right</button>
    <button class="u-btn" on-click={this.show(3)}>Bottom Center</button>
    <button class="u-btn" on-click={this.show(4)}>Bottom Left</button>
    <button class="u-btn" on-click={this.show(5)}>Bottom Right</button>
  1. var component = new NEKUI.Component({
    template: template,
    config: function() {
    this.notifies = [
    new NEKUI.Notify({data: {position: 'topcenter'} }),
    new NEKUI.Notify({data: {position: 'topleft'} }),
    new NEKUI.Notify({data: {position: 'topright'} }),
    new NEKUI.Notify({data: {position: 'bottomcenter'} }),
    new NEKUI.Notify({data: {position: 'bottomleft'} }),
    new NEKUI.Notify({data: {position: 'bottomright'} })
    ];
    },
    show: function(index) {
    var notify = this.notifies[index];
    notify.show('Position: ' + notify.data.position + '.');
    }
    });

嵌入文档流

上面的模式通知都是以fixed的形式固定在浏览器中,如果要将通知嵌入到文档流,先将notify注入到需要的位置,同时设置notifyposition="static"

通知 notify - 图4

  1. <button class="u-btn u-btn-primary" on-click={this.show()}>Static</button>
    <notify ref="notify" position="static" duration="0" />
  1. var component = new NEKUI.Component({
    template: template,
    show: function() {
    this.$refs.notify.show('Static notify.');
    }
    });

消息停留时间

可以通过设置notifyduration参数设置所有消息的停留时间,也可以在show的时候单独设置该条消息的停留时间,单位为毫秒。

通知 notify - 图5

  1. <button class="u-btn" on-click={this.show(500)}>0.5s</button>
    <button class="u-btn" on-click={this.show(1000)}>1s</button>
    <button class="u-btn" on-click={this.show(2000)}>2s</button>
    <button class="u-btn" on-click={this.show(0)}>常驻</button>
  1. var component = new NEKUI.Component({
    template: template,
    show: function(duration) {
    NEKUI.Notify.show('Duration: ' + duration + ' ms.', null, duration);
    }
    });

始终显示一条

single设置为true,可以让notify始终只显示一条消息。

通知 notify - 图6

  1. <button class="u-btn u-btn-info" on-click={this.show('info')}>Info</button>
    <button class="u-btn u-btn-success" on-click={this.show('success')}>Success</button>
    <button class="u-btn u-btn-warning" on-click={this.show('warning')}>Warning</button>
    <button class="u-btn u-btn-error" on-click={this.show('error')}>Error</button>
  1. var component = new NEKUI.Component({
    template: template,
    config: function() {
    this.notify = new NEKUI.Notify({data: {single: true} });
    },
    number: 1,
    show: function(state) {
    this.notify[state]('Message ' + this.number + '.');
    this.number++;
    }
    });

API

Classes

Members

  • notify
  • 直接初始化一个实例

Functions

Events

Notify

Kind: global classExtend: Component

new Notify()

ParamTypeDefaultDescription
[options.data]object= 绑定属性
[options.data.position]string"topcenter"=> 通知的位置,可选参数:topcentertoplefttoprightbottomcenterbottomleftbottomrightstatic
[options.data.duration]number2000=> 每条消息默认的停留毫秒数,如果为0,则表示消息常驻不消失。
[options.data.single]booleanfalse=> 是否始终显示一条
[options.data.visible]booleantrue=> 是否显示
[options.data.class]string=> 补充class

notify

直接初始化一个实例

Kind: global variableState: Notify

config()

Kind: global functionAccess: protected

init()

Kind: global functionAccess: protected

close(message) 关闭某条消息(message) ⇒ void

Kind: global functionAccess: public

ParamTypeDescription
messageobject需要关闭的消息对象

closeAll() 关闭所有消息() ⇒ void

Kind: global functionAccess: public

“show 弹出一个消息时触发”

Kind: event emittedProperties

NameTypeDescription
senderobject事件发送对象
messageobject弹出的消息对象

“close 关闭某条消息时触发”

Kind: event emittedProperties

NameTypeDescription
senderobject事件发送对象
messageobject关闭了的消息对象

.close(message) 关闭某条消息(message) ⇒ void

Kind: static functionAccess: public

ParamTypeDescription
messageobject需要关闭的消息对象

.closeAll() 关闭所有消息() ⇒ void

Kind: static functionAccess: public