0
点赞
收藏
分享

微信扫一扫

微信小程序-----(二)

拾光的Shelly 2022-04-19 阅读 81

事件绑定

通过bindtap,bindinput进行绑定,在ts中写其对应的函数

事件处理函数为data中的值赋新值

<button type="primary" bindtap="countChange">+1</button>
data: {
    count:0
    },
    countChange(){
        this.setData({
            count:this.data.count+1
        })
    },

通过this.setData()为data中的数据赋新值

传参

<button type="primary" data-info="{{1}}" bindtap="Bnt">+2</button>

    Bnt(e){
     this.setData({
         count: this.data.count + e.currentTarget.dataset.info
     })
    },

bindinput

<input type="text" bindinput="display"> </input>

    display(e){
     console.log(e.detail.value)
    },

e.detail.value 拿到输入的值

文本框和data之间的数据同步

<input value="{{msg1}}" type="text" bindinput="display"> </input>


    display(e){
       // console.log(e.detail.value)
       this.setData({
           msg1: e.detail.value
       })
       },


input{
    border:1px solid lightgreen;
    margin:5px;
     padding:5px;
     border-radius: 3px;
}

value

举报

相关推荐

0 条评论