1. 程式人生 > >vue---vue2.x中父元件如何觸發子元件事件方法?

vue---vue2.x中父元件如何觸發子元件事件方法?

import vHeader from './Header'; import vContent from './Content'; import vFooter from './Footer'; export default { components:{vHeader,vContent,vFooter}, methods:{ emitChild1(){ this.$refs.footer.$emit('bridge','你好嗎!'); //列印: 你好嗎
this.$refs.footer.$emit('bridge'); //列印:hello world }, emitChild2(){ this.$refs.footer.childAction('你好嗎!'); //列印: 你好嗎 this.$refs.footer.childAction(); //列印:hello world }, emitChild3(){ this
.$children[2].$emit('bridge','你好嗎!'); //列印: 你好嗎 this.$children[2].$emit('bridge'); //列印:hello world }, emitChild4(){ this.$children[2].childAction('你好嗎!'); //列印: 你好嗎 this.$children[2].childAction(); //列印:hello world
}, } }