-- 显示文本信息,文本信息保存在全局变量motto里
<view class="usermotto">
<
text
class=
"user-motto">{{motto}}
</
text
>
</
view
>
-- 组件 按钮的使用
*.wxml: <button bindtap='clickMe'> lick me </button>
*.js:
//click me
clickMe:
function () {
this.setData({motto:
"Zha Test"})
},
- 微信界面跳转
wx.navigateTo({
url:
'../logs/logs'
})
-- 提示对话窗体
wx.showModal({
title:
'提示',
content:
'创建用户失败!',
})
- 调用后台的操作
wx.request({
url:
'https://tzrobot.applinzi.com/yhzc.php',
data: {
yhm: zh,
mm: mm,
},
header: {
'content-type':
'application/jcon'
//默认值
},
success:
function (res) {
console.log(res.data)
app.globalData.tjjg =
"注册成功"
wx.navigateTo({
url:
"../me/me"
})
},
fail:
function (res) {
wx.showModal({
title:
'提示',
content:
'创建用户失败!',
})
}
})
-- wx.getUserInfo 获取微信用户的头像和昵称
-- wx.canIUse('button.open-type.getUserInfo')
-- wx:if="{{!hasUserInfo && canIUse}}"
-- wx:else
<
view
class=
"userinfo">
<
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
>
----------------------------------------------------------------------
data: {
motto:
'Hello World',
userInfo: {},
hasUserInfo:
false,
canIUse: wx.canIUse(
'button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap:
function() {
wx.navigateTo({
url:
'../logs/logs'
})
},
getUserInfo:
function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo:
true
})
}