0
点赞
收藏
分享

微信扫一扫

VUE3 Provide / Inject传递函数

凶猛的小白兔 2022-04-26 阅读 74
vue.js

通过 Provide / Inject将爷爷组件内的方法暴露给孙子组件调用

方法一:

爷爷组件代码

const Get_list = () => {
      console.log('Get_list 方法被执行')
    }
 provide('Call_Get_list',Get_list)

孙子组件代码

    const update=inject('Call_Get_list') as Function
    update()

方法二:源URL(没试验过)

爷爷组件代码

provide('isCompleted',isCompleted)

孙子组件代码

const isCompleteds = inject('isCompleted',Function,true)

举报

相关推荐

0 条评论