现在有三个函数,都在componentDidMount()生命周期中
componentDidMount() {
这里一直监听
_self.clientScript.subscribe('/topic/situation-transmit',function (data) {
var returnData = eval('(' + data.body + ')');
var date = new Date();
var showTime = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
console.log(showTime + ' = 接收到的数据 = ')
console.log(returnData.data);
_self.setState({
quantity: returnData.data['basicMessage']
})
})
开始发第一个消息
_self.clientScript.send(
'/topic/graduation-receive',
{},
JSON.stringify({
topic: '/topic/situation-transmit',
interval: 1,
screenType: 'situation'
})
);
这是第二个函数,我希望在发送第一个消息后,监听到返回的数据,再发第二个消息,应该怎么实现?,不想放到监听里面,因为监听会一直执行下面这个函数
_self.clientScript.send(
'/topic/graduation-receive',
{},
JSON.stringify({
topic: '/topic/situation-transmit',
interval: 1,
screenType: 'situation'
})
);
}
回调,promise,generator,async都可以