window自定义事件

1.定义方法名

options.detail = '测试';
/**
* 自定义事件, websoketCreate接收
*/
const event = new CustomEvent('watchWebsocket', options);
window.dispatchEvent(event);

2.接收

/**
 * 自定义事件, 接收onmessage返回的数据
 */
window.addEventListener(
	'watchWebsocket',
	(options) => {
		// console.log('subWsDepth订阅深度', options['detail']);
		const data = options['detail'];
		const channel = data.channel;
		const regDepth = /.*depth.*/; // 深度数据正则
		const regDeal = /^market_[a-z0-9]*_trade_ticker$/; // 成交数据正则
		const regMiner = /^push_time_miner_message_/; // 时间矿工

		// 深度图
		if (regDepth.test(channel)) {
			if (data.event_rep) return;
			// console.log('subWsDepth订阅深度', data);
			bus.$emit('regdepth', data);
		}
	},
	false
);

  

posted @ 2020-10-14 11:50  AlanTao  阅读(1377)  评论(0编辑  收藏  举报