vue子传父拦截器

Posted yummylucky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue子传父拦截器相关的知识,希望对你有一定的参考价值。

今天跟大佬学到一个子传父的方法。

父组件data中定义一个变量 a ,定义一个方法  interceptor (val) this.a = val 

然后将这个方法传入子组件: <child-node :interceptor="interceptor"></child-node> 

 

在子组件中接收这个方法: props:interceptor:type: Function 

在子组件中调用拦截器方法: this.interceptor(‘childMsg‘) 

 

在父组件中渲染便可以看到变量 a 中已经得到了子组件中传递的值。

以上是关于vue子传父拦截器的主要内容,如果未能解决你的问题,请参考以下文章