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
})
},