微信小程序学习之路 在html中绑定点击事件

1.在html标签中绑定tap事件
    <button bindtap="createMember">微信建档</button>
  • 1
2.在对应的js中写点击事件要做的事情
    createMember:function(e){
        const a = parseInt(Math.random() * 10)
        this.setData({
            name:'您的幸运号码是:'+a
        })
        var url = serverConfig.url + '/wechat'
        wx.request({
            url: url, 
            data: {
               x: '1' ,
               y: '2'
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function(res) {
              console.log(res.data)
            }
        })
    }

猜你喜欢

转载自blog.csdn.net/qq_36336522/article/details/79549050