$emit是子组件向父组件传值使用
使用方法一:
子组件调用父组件方法
$emit('fatherFn’)
子组件调用父组件方法并传参数
$emit(‘fatherFn’, arg1)
父组件接收方法获取arg1:
$emit('fatherFn', 10)
<sonComponent @fatherFn="str += $event"></sonComponent>
父组件接收方法2:
<sonComponent @fatherFn="fatherFn"></sonComponent>
如果想通过定义使用arg1,那么不可以自己定义变量,要使用$event.
fatherFn(val){console.log(val)}
注意如果接口调用的fatherFn方法中不写参数,可以fatherFn使用时,直接使用val