DeleteNews(bid){ uni.showModal({ title: '提示', content: '是否移除好友消息?', success: function(res) { if (res.confirm) { var conversationID = bid; //删除会话ID var conversationType = 0; //单聊 var config = { isAlsoDeleteServerMessage: true }; wx.$store.deleteAllMessage(conversationID, conversationType, config); wx.$store.deleteConversation(conversationID, conversationType, config); setTimeout(() => { wx.$store.queryConversationList(); }, 500); } } }); },修改代码,让他可以使用
时间: 2023-07-16 07:14:32 浏览: 97
你可以将代码修改为以下形式:
```
function DeleteNews(bid) {
uni.showModal({
title: '提示',
content: '是否移除好友消息?',
success: function(res) {
if (res.confirm) {
var conversationID = bid; //删除会话ID
var conversationType = 0; //单聊
var config = {
isAlsoDeleteServerMessage: true
};
uni.$emit('deleteAllMessage', conversationID, conversationType, config);
uni.$emit('deleteConversation', conversationID, conversationType, config);
setTimeout(() => {
uni.$emit('queryConversationList');
}, 500);
}
}
});
}
```
这里使用了 `uni.$emit` 方法来触发对应的事件,需要在其他地方监听这些事件并进行相应的处理。比如:
```
uni.$on('deleteAllMessage', function(conversationID, conversationType, config) {
wx.$store.deleteAllMessage(conversationID, conversationType, config);
});
uni.$on('deleteConversation', function(conversationID, conversationType, config) {
wx.$store.deleteConversation(conversationID, conversationType, config);
});
uni.$on('queryConversationList', function() {
wx.$store.queryConversationList();
});
```
这样就可以让函数可以使用了。
阅读全文