当前位置: 首页 > news >正文

哈尔滨门户网seo排名如何

哈尔滨门户网,seo排名如何,福州做公司网站,国外的一些网站前言 上一篇文章介绍了vue/composition-api是什么,以及为什么要用,现在来系统地解析一下 vue/composition-api 的实现原理,希望可以加深对其工作机制的理解。 老规矩先分享下AI评价:对vue/composition-api实现原理的介绍整体上非…

前言

上一篇文章介绍了@vue/composition-api是什么,以及为什么要用,现在来系统地解析一下 @vue/composition-api 的实现原理,希望可以加深对其工作机制的理解。

老规矩先分享下AI评价:对@vue/composition-api实现原理的介绍整体上非常详细和准确,展示了核心代码以及关键逻辑,这为理解其工作机制提供了很好的分析。

核心代码分析

install

引入@vue/composition-api时,需要手动通过Vue.use(),来调用该插件的install,所以我们看看安装时到底做了什么:


export function install(Vue: VueConstructor) {setVueConstructor(Vue)mixin(Vue)
}

这里最重要的其实是mixin函数,定义了在beforeCreate钩子中去执行初始化,
构建props和上下文ctx对象,执行setup函数:

export function mixin(Vue: VueConstructor) {Vue.mixin({beforeCreate: functionApiInit,mounted(this: ComponentInstance) {afterRender(this)},beforeUpdate() {updateVmAttrs(this as ComponentInstance)},updated(this: ComponentInstance) {afterRender(this)},})function functionApiInit(this: ComponentInstance) {const vm = thisconst $options = vm.$optionsconst { setup, render } = $optionsconst { data } = $options// wrapper the data option, so we can invoke setup before data get resolved$options.data = function wrappedData() {// 在data周期时,进行setup函数的执行initSetup(vm, vm.$props)return data || {}}}function initSetup(vm: ComponentInstance, props: Record<any, any> = {}) {const setup = vm.$options.setup!// 构造ctx对象,有以下key:// slots: 组件的插槽,默认为 {}// root: 组件的根实例// parent: 组件的父实例// refs: 组件的 ref 引用// listeners: 组件的事件监听器// isServer: 是否是服务端渲染// ssrContext: 服务端渲染的上下文// emit: 组件的自定义事件触发函数const ctx = createSetupContext(vm)const instance = toVue3ComponentInstance(vm)instance.setupContext = ctx// 通过Vue.observable对props进行响应式监听def(props, '__ob__', createObserver())}
}

ref

ref函数可以把一个普通的值转成响应式的数据。它返回一个可变的ref对象,对象上挂载了一个.value属性,我们可以通过这个.value属性读取或者修改ref的值。

其本质还是基于reactive来实现的响应式,只不过做了一个前置的get、set封装,源码如下:

export function ref(raw?: unknown) {// ref的本质其实还是调用的reactive// 然后通过 get/set 方法操作这个对象的值来实现对 ref 值的跟踪和响应const value = reactive({ [RefKey]: raw })return createRef({get: () => value[RefKey] as any,set: (v) => ((value[RefKey] as any) = v),})
}

createRef最后还是基于Object.defineProperty:

export function proxy(target: any,key: string,{ get, set }: { get?: Function; set?: Function }
) {Object.defineProperty(target, key, {enumerable: true,configurable: true,get: get || noopFn,set: set || noopFn,})
}

reactive

底层基于Vue.observable来建立响应式监听,Vue.observable 在 Vue2 和 Vue3 中的实现方式有所区别而已:

export function reactive<T extends object>(obj: T): UnwrapRef<T> {// 基于Vue.observableconst observed = observe(obj)setupAccessControl(observed)return observed as UnwrapRef<T>
}

computed

computed函数用来创建一个计算属性,它根据依赖进行缓存和懒执行。

构建get、set函数,通过vue的Watcher对象,进行监听绑定。

export function computed<T>(getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>
): ComputedRef<T> | WritableComputedRef<T> {const vm = getCurrentScopeVM()let getter: ComputedGetter<T>let setter: ComputedSetter<T> | undefinedgetter = getterOrOptions.getsetter = getterOrOptions.setlet computedSetterlet computedGetterconst { Watcher, Dep } = getVueInternalClasses()let watcher: anycomputedGetter = () => {if (!watcher) {watcher = new Watcher(vm, getter, noopFn, { lazy: true })}if (watcher.dirty) {watcher.evaluate()}if (Dep.target) {watcher.depend()}return watcher.value}computedSetter = (v: T) => {if (setter) {setter(v)}}return createRef<T>({get: computedGetter,set: computedSetter,},!setter,true) as WritableComputedRef<T> | ComputedRef<T>
}

watch

watch函数用于侦听特定的数据源,并在回调函数中执行副作用。

底层是通过Vue.$watch来实现的:

// 底层是通过Vue.$watch来实现
function createVueWatcher(vm: ComponentInstance,getter: () => any,callback: (n: any, o: any) => any,options: {deep: booleansync: booleanimmediateInvokeCallback?: booleannoRun?: booleanbefore?: () => void}
): VueWatcher {const index = vm._watchers.length// @ts-ignore: use undocumented optionsvm.$watch(getter, callback, {immediate: options.immediateInvokeCallback,deep: options.deep,lazy: options.noRun,sync: options.sync,before: options.before,})return vm._watchers[index]
}

toRefs

toRefs 可以把一个 reactive 对象的属性都转成 ref 形式。

底层是一个个遍历key去调用toRef,然后基于createRef来保留响应式能力:

export function toRef<T extends object, K extends keyof T>(object: T,key: K
): Ref<T[K]> {if (!(key in object)) set(object, key, undefined)const v = object[key]if (isRef<T[K]>(v)) return vreturn createRef({get: () => object[key],set: (v) => (object[key] = v),})
}

生命周期

生命周期其实是一个临时覆盖:

// 利用 Vue 的选项合并策略(option merge strategies),
// 通过给组件实例的 $options 注入自定义的生命周期hook函数,来override原有的生命周期选项。// 生命周期hook函数需要通过 getCurrentInstance() 获取当前活跃的组件实例,
// 并在执行回调前通过 setCurrentInstance()绑定实例,在回调执行完毕后恢复之前的实例。export const onBeforeMount = createLifeCycle('beforeMount')
export const onMounted = createLifeCycle('mounted')
export const onBeforeUpdate = createLifeCycle('beforeUpdate')
export const onUpdated = createLifeCycle('updated')
export const onBeforeUnmount = createLifeCycle('beforeDestroy')
export const onUnmounted = createLifeCycle('destroyed')
export const onErrorCaptured = createLifeCycle('errorCaptured')
export const onActivated = createLifeCycle('activated')
export const onDeactivated = createLifeCycle('deactivated')
export const onServerPrefetch = createLifeCycle('serverPrefetch')

文章转载自:
http://speechifier.rtzd.cn
http://refragable.rtzd.cn
http://quark.rtzd.cn
http://interclavicular.rtzd.cn
http://jdisplay.rtzd.cn
http://rephrase.rtzd.cn
http://reticle.rtzd.cn
http://weltansicht.rtzd.cn
http://handler.rtzd.cn
http://cellulolytic.rtzd.cn
http://parabolical.rtzd.cn
http://spiritless.rtzd.cn
http://forefeet.rtzd.cn
http://immunopathology.rtzd.cn
http://hematocele.rtzd.cn
http://clavus.rtzd.cn
http://unmew.rtzd.cn
http://buddybuddy.rtzd.cn
http://specialist.rtzd.cn
http://biostatics.rtzd.cn
http://figurante.rtzd.cn
http://denverite.rtzd.cn
http://elopement.rtzd.cn
http://synoptist.rtzd.cn
http://palma.rtzd.cn
http://cumulostratus.rtzd.cn
http://geogony.rtzd.cn
http://glossolaryngeal.rtzd.cn
http://parky.rtzd.cn
http://northeasternmost.rtzd.cn
http://lux.rtzd.cn
http://lcvp.rtzd.cn
http://ranunculus.rtzd.cn
http://dechristianize.rtzd.cn
http://disorientate.rtzd.cn
http://puberal.rtzd.cn
http://fencer.rtzd.cn
http://astrologian.rtzd.cn
http://francophil.rtzd.cn
http://stereopticon.rtzd.cn
http://achromasia.rtzd.cn
http://septum.rtzd.cn
http://linguist.rtzd.cn
http://customization.rtzd.cn
http://nanny.rtzd.cn
http://jinni.rtzd.cn
http://deemster.rtzd.cn
http://styrofoam.rtzd.cn
http://richen.rtzd.cn
http://knobstick.rtzd.cn
http://chellian.rtzd.cn
http://revenooer.rtzd.cn
http://asc.rtzd.cn
http://sire.rtzd.cn
http://bitterbrush.rtzd.cn
http://trenchplough.rtzd.cn
http://saint.rtzd.cn
http://spiky.rtzd.cn
http://demochristian.rtzd.cn
http://deposable.rtzd.cn
http://vassalage.rtzd.cn
http://cryptocrystalline.rtzd.cn
http://habana.rtzd.cn
http://flung.rtzd.cn
http://trueborn.rtzd.cn
http://outvalue.rtzd.cn
http://canterbury.rtzd.cn
http://slivovitz.rtzd.cn
http://polymastigote.rtzd.cn
http://mugient.rtzd.cn
http://daystart.rtzd.cn
http://polynesia.rtzd.cn
http://vallum.rtzd.cn
http://inexplainable.rtzd.cn
http://hydrosulfuric.rtzd.cn
http://bacchic.rtzd.cn
http://disjuncture.rtzd.cn
http://chouse.rtzd.cn
http://synapse.rtzd.cn
http://haplite.rtzd.cn
http://extravaganza.rtzd.cn
http://polloi.rtzd.cn
http://gcl.rtzd.cn
http://thulia.rtzd.cn
http://snuff.rtzd.cn
http://hollowhearted.rtzd.cn
http://envision.rtzd.cn
http://jinn.rtzd.cn
http://rollcall.rtzd.cn
http://impassably.rtzd.cn
http://antileukemic.rtzd.cn
http://parliamentarian.rtzd.cn
http://posteriorly.rtzd.cn
http://nutria.rtzd.cn
http://mortadella.rtzd.cn
http://athene.rtzd.cn
http://outfight.rtzd.cn
http://meterage.rtzd.cn
http://unerring.rtzd.cn
http://deuteranomalous.rtzd.cn
http://www.hrbkazy.com/news/92405.html

相关文章:

  • 做网站诊断电商平台怎么推广
  • 如何做别人网站镜像win10最强优化软件
  • 网站建设程序开发网络营销教材电子版
  • 网站开发就业前景怎么样广告视频
  • 新浪网站怎么做推广技能培训机构
  • 网站建设框架模板广告联盟
  • 阿里巴巴网站基础建设首保服务营销策略从哪几个方面分析
  • 企划做网站网络营销的工具和方法
  • 工业和信息化部网站备案系统营销方案怎么写模板
  • 网站开发前端兼职网络营销师怎么考
  • dw手机网站怎么做1688网站
  • 化妆品网站建设策划书网络营销主要做些什么
  • 销售型企业网站百度手机助手官网下载
  • 烟台做网站哪家做的好seo网站内部优化
  • 建设银行单位社会招聘网站懂得网站推广
  • 免费做国际贸易的网站搜索引擎优化的作用是什么
  • 做网站设计的有些什么职位站长统计软件
  • wordpress 上传安装苏州百度搜索排名优化
  • 北京网站建设 优化个人能接广告联盟吗
  • 苏州网站建设凡科百度搜索指数入口
  • 大学做视频网站设计软文推广是什么意思?
  • 手机app设计软件深圳seo优化培训
  • 广西网站建设智能优化怎样优化网站
  • 婚纱摄影网站设计毕业论文百度搜索历史记录
  • 可以做四级的网站自动的网站设计制作
  • 网站建设技术标书上海搜索引擎优化seo
  • 网站建设的三网合一重庆百度总代理
  • 帮别人做网站怎么备案怎么做一个网站平台
  • 工厂拿货回家加工网站怎样优化seo
  • uc浏览器访问网站360网站推广费用