今天很开心,get了3个知识点
1、首先搞懂了bindtap和bindinput的区别;
bindinput在input标签里面,输入框的每次输入都会触发bindinput绑定的方法;
bindtap在其他标签,比如button。button的每次点击都会出发bindtap绑定的方法;
<view wx:for="{{students}}" wx:key="item">
{{index+1}}:{{item}}
</view>
<input type="text" bindinput="getStudent"/>
<button bindtap="addStudent">增加学生</button>
2、另外就是掌握了this.setDta,对data中变量的修改;
this.data.students.push(this.student)
console.log(this.data.students)
this.setData({
students: this.data.students
})
3、了解了wx.setStorage和wx.getStorage的用法。对当前的data数据进行缓存和取缓存。
Page({
data: {
students: []
},
getStudent(e) {
console.log(e.detail.value)
this.student = e.detail.value
},
addStudent() {
console.log(this.student)
this.data.students.push(this.student)
console.log(this.data.students)
this.setData({
students: this.data.students
})
wx.setStorage({
key: 'students',
data: this.data.students
})
},
onLoad() {
wx.getStorage({
key: 'students',
success: (res) => {
console.log(res.data)
this.setData({
students: res.data
})
}
})
}
})