前端之vue3使用积累

一.父子组件通讯

父→子

provide(提供)与inject(注入)

适用于父子, 祖孙

1.传递方法

①父:

    provide("getReport", getReport);
    //参数:
	//1: "getReport"是子组件注入是要用到的key
    //2: getReport是一个方法

②子:

    const getReport = inject("getReport");
getReport:
// 第一个是在子组件中使用时用到的名称
// 第二个是接收父组件提供的key为getReport的方法

猜你喜欢

转载自blog.csdn.net/weixin_46372074/article/details/125168890