一、父組件調用子組件方法
子組件方法:
// 組件的方法列表
methods: {
test(){
console.log('我是子組件方法')
}
},
父組件調用:
<test id="two"/>
在自定義方法裏調用即可
this.selectComponent('#two').test();
二、子組件調用父組件方法
父組件方法
<test bind:submit="submit" ></test>
submit(event) {
console.log(event);
},
子組件用this.triggerEvent('父組件自定義事件', '要傳遞的參數')
,觸發父組件傳過來的自定義事件
Component({
properties: {
totalMoney: {
type: Number,
value: 0, //默認
}
},
methods:{
//子組件事件
btnclick(){
console.log('aaaaaaaaaaaaaaaaaaa');
this.triggerEvent("submit", 'Hello lily')
}
}
})