// /pages/index/index.js
page({
plus() {
this.counter.plus();
}, // saveref 方法的参数 ref 为自定义组件实例,运行时由框架传递给 saveref
saveref(ref) {\t// 存储自定义组件实例,方便以后调用
this.counter = ref;
},
});
//pages/index/index.axml
<my-component ref="saveref" /><button ontap="plus"> button>
// /components/index/index.js
component({
data: {
counter: 0,
},
methods: {
plus() {
this.setdata({ counter: this.data.counter 1 })
},
},
})