看了文档 说是只有支付宝云支持websocket ,其他的云服务就是watch和websocket 都不支持,不太便捷。需要确认一下unicloud不支持watch监听数据库变化吗?这个文档里面没有明确说明
// 尝试使用更简单的监听方式
this.watchRef = this.collection.watch({
onChange: (snapshot) => {
console.log('监听到数据变化:', snapshot);
this.addLog(监听到变化: ${snapshot.type} - ${snapshot.docId || '批量操作'});
// 更新连接状态为已连接
this.connectionStatus = 'connected';
// 重新加载数据
this.loadData();
},
onError: (error) => {
console.error('监听错误:', error);
this.addLog(`监听错误: ${error.message || error}`);
this.connectionStatus = 'error';
// 尝试重新连接
setTimeout(() => {
this.addLog('尝试重新连接...');
this.startWatch();
}, 3000);
}
});
demo测试了onChange 根本没有反应