Skip to content

Instantly share code, notes, and snippets.

@zhangkn
Created May 17, 2018 06:58
Show Gist options
  • Save zhangkn/e1204304f6ab24586a03c0cce7bf22e5 to your computer and use it in GitHub Desktop.
Save zhangkn/e1204304f6ab24586a03c0cce7bf22e5 to your computer and use it in GitHub Desktop.
条件渲染
<view class="userinfo">
<!--1、使用 button 组件,并将 open-type 指定为 getUserInfo 类型,获取用户基本信息 //获取数据 -->
<!-- /2、使用 open-data 展示用户基本信息。 -->
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
Page({
data: {
text: 'Click me get my posts!',
motto: helloData,
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')//使用 button 组件,并将 open-type 指定为 getUserInfo 类型,获取用户基本信息
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment