provide --- inject

父组件

provide () {

  const vm = this

  return {

    getinternalApi (api) {

      vm.audioapi = api

    }

  }

}

子组件

inject: [''getinternalApi]

computed: {

  if(typeof this.getinternalApi=== 'function'){

    this.getinternalApi({

      pause:this.pause.bind(this)

    })

  }

}

猜你喜欢

转载自www.cnblogs.com/cs122/p/11980888.html