This article shares the specific code of WeChat applet to implement the chat room through examples for your reference. The specific content is as follows 1. Achieve effect display 2.room.wxml <view class="container" style="{{containerStyle}}"> <chatroom style="width: 100%; height: 100%" envId="{{chatRoomEnvId}}" collection="{{chatRoomCollection}}" groupId="{{chatRoomGroupId}}" groupName="{{chatRoomGroupName}}" userInfo="{{userInfo}}" onGetUserInfo="{{onGetUserInfo}}" getOpenID="{{getOpenID}}" ></chatroom> </view> 3.room.js const app = getApp() Page({ data: { avatarUrl: './user-unlogin.png', userInfo: null, logged: false, takeSession: false, requestResult: '', // chatRoomEnvId: 'release-f8415a', chatRoomCollection: 'chatroom', chatRoomGroupId: 'demo', chatRoomGroupName: 'Chat Room', // functions for used in chatroom components onGetUserInfo: null, getOpenID: null, }, onLoad: function() { // Get user information wx.getSetting({ success: res => { if (res.authSetting['scope.userInfo']) { // Already authorized, you can directly call getUserInfo to get the avatar nickname without a pop-up window wx.getUserInfo({ success: res => { this.setData({ avatarUrl: res.userInfo.avatarUrl, userInfo: res.userInfo }) } }) } } }) this.setData({ onGetUserInfo: this.onGetUserInfo, getOpenID: this.getOpenID, }) wx.getSystemInfo({ success: res => { console.log('system info', res) if (res.safeArea) { const { top, bottom } = res.safeArea this.setData({ containerStyle: `padding-top: ${(/ios/i.test(res.system) ? 10 : 20) + top}px; padding-bottom: ${20 + res.windowHeight - bottom}px`, }) } }, }) }, getOpenID: async function() { if (this.openid) { return this.openid } const { result } = await wx.cloud.callFunction({ name: 'login', }) return result.openid }, onGetUserInfo: function(e) { if (!this.logged && e.detail.userInfo) { this.setData({ logged: true, avatarUrl: e.detail.userInfo.avatarUrl, userInfo: e.detail.userInfo }) } }, onShareAppMessage() { return { title: 'Instant Messaging Demo', path: '/pages/im/room/room', } }, }) 4.room.json { "usingComponents": { "chatroom": "/components/chatroom/chatroom" } } 5.room.wxss .container { height: 100%; position: absolute; top: 0; bottom: 0; left: 0; right: 0; padding-top: 80rpx; padding-bottom: 30rpx; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Tutorial on installing Docker in Windows 10 subsystem Ubuntu (WSL) (with pictures and text)
>>: Summary of MySQL common SQL statements including complex SQL queries
Preface Sometimes you need to keep the height of ...
download Download address: https://redis.io/downl...
0x00 Introduction A few months ago, I found a vul...
Create a new project test1 on Code Cloud Enter th...
Main library binlog: # at 2420 #170809 17:16:20 s...
Today is 618, and all major shopping malls are ho...
Table of contents 1. What is virtual dom? 2. Why ...
This article example shares the specific code of ...
When creating a tomcat server on a local eclipse,...
Table of contents Preface Background data splicin...
Introduction: Regarding MySQL database specificat...
Table of Contents Introduction Synchronous Asynch...
Table of contents mysql permission control Permis...
Jenkins configuration of user role permissions re...
I have always wondered why the MySQL database tim...