微信小程序选项卡功能开发步骤与方法全解析
628
2022-11-23
Ionic3 发布/订阅
Ionic3 发布/订阅
官网文档地址: { Events } from 'ionic-angular'; //导入...export class EventsPage { user = '来自Events的数据' constructor(public events: Events) {} publishEvents(user) { console.log('User created!') this.events.publish('user:created',this.user, Date.now()); console.log(this.user) }}
订阅
import { Component} from '@angular/core';import { Events } from 'ionic-angular';@Component({ selector: 'page-home', templateUrl: 'home.html'})export class HomePage { myEvent; constructor(public events: Events) { events.subscribe('user:created', (user, time) => { HomePage.prototype.myEvent = user; }); }}
publish(topic, eventData)
发布主题
类型 | 说明 | |
topic | string | 发布的主题 |
eventData | any | 数据 |
subscribe(topic, handler)
订阅数据
参数 | 类型 | 说明 |
topic | string | the topic to subscribe to |
handler | function | the event handler |
unsubscribe(topic, handler)
取消订阅
参数 | 类型 | 说明 |
topic | string | the topic to unsubscribe from |
handler | function | the event handler |
返回值:如果被移除成功,返回true
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~