open-data

View Markdown

User information-related features have been adjusted. See the announcement at Mini Program Announcement on Adjustments to User Information-Related APIs for details.

Base Library 1.4.0 or later is required. For earlier versions, see compatibility handling.

Plugin: Not supported

WeChat for Windows: Supported

WeChat for macOS: Supported

WeChat for HarmonyOS: Supported

Rendering framework support: Skyline (debug using the latest Nightly tools), WebView

Feature Description

Used to display data shared by the WeChat Open Platform.

Common Attributes

Attribute Type Default Required Description Minimum Version
type string No Open data type 1.4.0
Valid Value Description Minimum Version
groupName Fetches the group name 1.4.0
userNickName User nickname. No longer returned; displays as "WeChat User" 1.9.90
userAvatarUrl User avatar. No longer returned; displays Gray Avatar 1.9.90
userGender User gender. No longer returned; displays as empty ("") 1.9.90
userCity City where the user is located. No longer returned; displays as empty ("") 1.9.90
userProvince Province where the user is located. No longer returned; displays as empty ("") 1.9.90
userCountry Country where the user is located. No longer returned; displays as empty ("") 1.9.90
userLanguage User's language. No longer returned; displays as empty ("") 1.9.90
open-gid string No Effective when type="groupName"; Group ID 1.4.0
lang string en No Effective when type="user*"; Specifies the language in which userInfo is displayed 1.4.0
Valid Values Description
en English
zh_CN Simplified Chinese
zh_TW Traditional Chinese
default-text string No Default text when data is empty 2.8.1
default-avatar string No Default image when user avatar is empty. Supports relative paths and network image URLs 2.8.1
bind:error eventhandle No Triggered when group name or user information is empty 2.8.1

Skyline-specific Properties

Property Type Default Value Required Description Minimum Version
type string No Type of Open Data 3.7.11
Valid Values Description Minimum Version
groupName Retrieve group name 3.7.11
default-text string No Default text when data is empty 3.7.11

Bug & Tip

  1. tip: You can only retrieve the group name if the current user is in this group
  2. tip: To obtain the open-gid, please use wx.getShareInfo

Sample Code

Preview in DevTools

<open-data type="groupName" open-gid="xxxxxx"></open-data>
<open-data type="userAvatarUrl"></open-data>
<open-data type="userGender" lang="zh_CN"></open-data>