父组件调用子组件的方法以及子组件调用父组件的方法

来源:互联网 发布:js 过去选中的radio 编辑:程序博客网 时间:2024/06/06 02:02

1、父组件调用子组件的方法

父组件中:(关键字$refs、ref)

<component ref="childFunc"></component>

this.$refs.childFunc.childAlert(); 

子组件中:

childAlert () {    alert('被父组件调用到了!')}


2、子组件调用父组件的方法

父组件中:

<component @fatherfunction="fatherfunction"></component>
fatherfunction(val) {    alert(val)}


子组件中:(关键字$emit)

this.$emit('fatherfunction', '父组件被调用');



原创粉丝点击