vue3provide和reject

更新时间:2023-07-02 10:24:34 阅读: 评论:0

vue3provide和reject
//APP.vue  ⽗组件传递值
// tup(){
//    let num = ref(1)
//    provide('num',num)
// }
//⼦组件接收值
// tup(){
//    var result = inject('num')
练字的10大好处//    console.log(result)
// }
let currentInstance = null;
function provide(key, value) {
if (!currentInstance) {
{
warn$1(`provide() can only be ud inside tup().`);
}
}
el {
let provides = currentInstance.provides;
// by default an instance inherits its parent's provides object
// but when it needs to provide values of its own, it creates its
/电脑维修工具
/ own provides object using parent provides object as prototype.
// this way in `inject` we can simply look up injections from direct
// parent and let the prototype chain do the work.
//默认情况下,实例继承其⽗对象
//但当它需要提供⾃⼰的价值时,它就会创造⾃⼰的价值
//own使⽤⽗对象作为原型提供对象。
儿童健康零食
//通过这种⽅式,在'inject'中,我们可以简单地从direct中查找注⼊
//创建⽗对象并让原型链完成⼯作。
const parentProvides = currentInstance.parent && currentInstance.parent.provides;
if (parentProvides === provides) {
provides = currentInstance.provides = ate(parentProvides);
}
// TS doesn't allow symbol as index type
//TS不允许将符号作为索引类型
provides[key] = value;
}
}
function inject(key, defaultValue, treatDefaultAsFactory = fal) {
// fallback to `currentRenderingInstance` so that this can be called in
// a functional component
//回退到'currentRenderingInstance',以便可以在中调⽤它
//功能部件
const instance = currentInstance || currentRenderingInstance;
赐予
if (instance) {
// #2400
关于读书的议论文
// to support `app.u` plugins,
// fallback to appContext's `provides` if the intance is at root
//要⽀持'app.u'插件,
//如果intance位于根⽬录下,则回退到appContext的'provides'
const provides = instance.parent == null
instance.vnode.appContext && instance.vnode.appContext.provides
: instance.parent.provides;
if (provides && key in provides) {
/
/ TS doesn't allow symbol as index type
return provides[key];
}
el if (arguments.length > 1) {
return treatDefaultAsFactory && isFunction(defaultValue)
return treatDefaultAsFactory && isFunction(defaultValue)
defaultValue.call(instance.proxy)
: defaultValue;
}
2018春节联欢晚会
el {
warn$1(`injection "${String(key)}" not found.`);
中信部
}
}
el {
warn$1(`inject() can only be ud inside tup() or functional components.`);    }
}

本文发布于:2023-07-02 10:24:34,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1064443.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:对象   作为   提供   原型   组件   实例
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图