在原有的示例工程中增加按键功能:
1.首先点开index.wxml文件,添加如下代码
<view style="margin-top:30px;"> <button bindtap="enterclick"
style="font-size:28px; width:fit-content; height:fit-content;background-color:{{color2}}">确定</button> </view>
2.点开index.js文件,在page里面添加如下代码
enterclick: function() {
//当点击确定按钮
var that = this
that.setData({
powerstatus:"打卡",
color1:'white',
color2:'rgb(35,235,225)'
})
//控制接口
wx.request({
url: 'https://api.bemfa.com/api/device/v1/data/1/', //api接口,详见接入文档
method:"POST",
data: {
uid: that.data.uid,
topic: that.data.topic,
msg:"enter"
},
header: {
'content-type': "application/x-www-form-urlencoded"
},
success (res) {
console.log(res.data)
wx.showToast({
title:'打卡成功',
icon:'success',
duration:1000
})
}
})
},