一,数据、方法和属性
1.data 数据
在小程序组件中,用于组件模板渲染的私有数据,需要定义到 data 节点中:
2. methods 方法
在小程序组件中,事件处理函数和自定义方法需要定义到 methods 节点中
在组件的 .json 文件中新增如下配置
{
"styleIsolation":"isolated"
}
// components/test/test.js
Component({
// 组件的初始数据
data: {
count:
},
})
methods: {
//组件的方法列表【包含事件处理函数和自定义方法】
addCount() {
//事件处理函数
this.setData({
count: this.data.count + 1})
this._showCount() //通过this 直接调用自定义方法
}
},
_showCount(){
//自定义方法建议以_开头
wx