小程序頁面布局,獲取用戶信息
阿新 • • 發佈:2019-02-26
function down tab download 元素 屬性 adf bar quest
1, app.json 全局配置文件
①底部導航欄設置:(最少2個。最多5個)
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",//url
"text": "首頁"//title
},
{
"pagePath": "pages/logs/logs",
"text": "日誌"
}
]
},
//網絡超時時間:
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
2.邏輯層:
①數據綁定:
if:(index.wxml)
<view wx:if="{{condition}}"></view>
(index.js)
Page({
data: {
condition: true
}
})
if-elif-else
<view wx:if="{{length > 5}}">1</view>
<view wx:elif="{{length > 2}}">2</view>
<view wx:else>3</view>
for:
②
<view wx:for="{{[1,2,3]}} ">
{{item}}
</view>
(渲染數據 默認當前下標為index,當前元素為item)
<view wx:for="{{array}}">
{{index}}: {{item.message}}
</view>
<view wx:for="{{array}}" wx:for-index="idx" wx:for-item="itemName">
{{idx}}: {{itemName.message}}
</view>(改變下標和元素)
Page({
data: {
array: [{
message: ‘foo‘,
}, {
message: ‘bar‘
}]
}
})
3.
表單、按鈕
<button type=‘primary‘ bindtap=‘index‘>{{index}}</button>
{{index}}:index.js中添加屬性
index:function(){
wx.navigateTo({
url: "index"
})
},
4.獲取用戶信息
①
index.wxml
<button open-type=‘getUserInfo‘ bindgetuserinfo=‘getUserInfo‘>獲取用戶信息</button>
用戶信息展示
<view>昵稱:{{nickname}}</view>
<view>國家:{{country}}</view>
<image src="{{avatarUrl}}"/>
②index.js
getUserInfo:function(e){
console.log(e);
var userInfo=e.detail.userInfo
this.setData({
nickname: userInfo.nickname,
country: userInfo.country,
avatarUrl: userInfo.avatarUrl
})
},
小程序頁面布局,獲取用戶信息