微信小程序添加按键功能

在原有的示例工程中增加按键功能:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值