返回一个方法给子组件 方法内部返回数据
响应式
-
父组件
props: ['infoData'], provide() { return { info: this.getInfo } }, data: function () { return { info: '', } }, methods: { // 发送请求 根据id查询个人数据信息 async getInformationById () { // let result = await getInfofunc( {id: this.params.id} ) // 测试用于自动登录 let result = await getInfofunc( {id: 1} ) this.info = result console.log('info', this.info); }, getInfo () { return this.info } }
-
子组件
inject: { info: { type: Object } }, methods: { console.log("header-info",this.info()) }