vue3 options模式

applyOptions

外部

内部

1.resolveMergedOptions

2.beforeCreate

3.resolveInjections

js 复制代码
    const provides = instance ? instance.parent == null ? instance.vnode.appContext && instance.vnode.appContext.provides : instance.parent.provides : currentApp._context.provides;

4.methods

js 复制代码
   Object.defineProperty(ctx, key, {
            value: methodHandler.bind(publicThis),
            configurable: true,
            enumerable: true,
            writable: true
          });
        } else {
          ctx[key] = methodHandler.bind(publicThis);

5.dataOptions

js 复制代码
    const data = dataOptions.call(publicThis, publicThis);

6.computedOptions

js 复制代码
 for (const key in computedOptions) {
      const opt = computedOptions[key];
      const get =  opt.get.bind(publicThis, publicThis)
      const set = opt.set.bind(publicThis)
      const c = computed({
        get,
        set
      });
      Object.defineProperty(ctx, key, {
        enumerable: true,
        configurable: true,
        get: () => c.value,
        set: (v) => c.value = v
      });

7.watchOptions

js 复制代码
 for (const key in watchOptions) {
      createWatcher(watchOptions[key], ctx, publicThis, key);
    }
    
  const getter = key.includes(".") ? createPathGetter(publicThis, key) : () => publicThis[key];
    const handler = ctx[raw];
   const handler = isFunction(raw.handler) ? raw.handler.bind(publicThis) : ctx[raw.handler];

 watch(getter, handler);
 watch(getter, raw.bind(publicThis));
 watch(getter, handler, raw);

8.provideOptions

js 复制代码
  let provides = currentInstance.provides;
    const parentProvides = currentInstance.parent && currentInstance.parent.provides;
    if (parentProvides === provides) {
      provides = currentInstance.provides = Object.create(parentProvides);
    }
    provides[key] = value;
    if (currentInstance.type.mpType === "app") {
      currentInstance.appContext.app.provide(key, value);
    }

9.created

js 复制代码
    callHook$1(created, instance, "c");

10.registerLifecycleHook

js 复制代码
  function registerLifecycleHook(register, hook) {
    if (isArray(hook)) {
      hook.forEach((_hook) => register(_hook.bind(publicThis)));
    } else if (hook) {
      register(hook.bind(publicThis));
    }
  }
  registerLifecycleHook(onBeforeMount, beforeMount);
  registerLifecycleHook(onMounted, mounted);
  registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  registerLifecycleHook(onUpdated, updated);
  registerLifecycleHook(onActivated, activated);
  registerLifecycleHook(onDeactivated, deactivated);
  registerLifecycleHook(onErrorCaptured, errorCaptured);
  registerLifecycleHook(onRenderTracked, renderTracked);
  registerLifecycleHook(onRenderTriggered, renderTriggered);
  registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  registerLifecycleHook(onUnmounted, unmounted);
  registerLifecycleHook(onServerPrefetch, serverPrefetch);

11.expose

js 复制代码
 if (isArray(expose)) {
    if (expose.length) {
      const exposed = instance.exposed || (instance.exposed = {});
      expose.forEach((key) => {
        Object.defineProperty(exposed, key, {
          get: () => publicThis[key],
          set: (val) => publicThis[key] = val
        });
      });
    } else if (!instance.exposed) {
      instance.exposed = {};
    }
  }

11.render

js 复制代码
if (render && instance.render === NOOP) {
    instance.render = render;
  }

12.inheritAttrs

js 复制代码
 if (inheritAttrs != null) {
    instance.inheritAttrs = inheritAttrs;
  }

13.components

js 复制代码
 if (components)
    instance.components = components;

14.directives

js 复制代码
  if (directives)
    instance.directives = directives;

15.customApplyOptions

js 复制代码
  const customApplyOptions = instance.appContext.config.globalProperties.$applyOptions;
if (customApplyOptions) {
    customApplyOptions(options, instance, publicThis);
  }
相关推荐
万少10 小时前
我是如何使用 Trae IDE 完成《流碧卡片》项目的完整记录
前端·后端·ai编程
9***Y4810 小时前
前端微服务
前端·微服务·架构
ByteCraze10 小时前
我整理的大文件上传方案设计
前端·javascript
前端小白۞10 小时前
vue2 md文件预览和下载
前端·javascript·vue.js
十里-10 小时前
为什么创建1x1的gif图片,和png 或者jpg图片有什么区别
前端
u***u68510 小时前
Vue云原生
前端·vue.js·云原生
OpenTiny社区10 小时前
TinyEngine 低代码实时协作揭秘:原理 +实操,看完直接用!
前端·vue.js·低代码
喵个咪11 小时前
go-kratos-admin 技术栈深度解析:为什么选 Golang+Vue3 这套组合?
vue.js·go
5***790011 小时前
Vue项目性能优化
前端·javascript·vue.js
天若有情67312 小时前
【c++】手撸C++ Promise:从零实现通用异步回调组件,支持链式调用+异常安全
开发语言·前端·javascript·c++·promise