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

网站制作是怎样做的搜索引擎优化的常用方法

网站制作是怎样做的,搜索引擎优化的常用方法,设计网站做海报,郑州高端网站定制建设目录 说明例子processComponentcomponentUpdateFnupdateComponentupdateComponentPreRender 总结 说明 由于响应式相关内容太多,决定先接着上文组件挂载后,继续分析组件后续更新流程,先不分析组件是如何分析的。 例子 将这个 用例 使用 vi…

目录

    • 说明
    • 例子
    • processComponent
      • componentUpdateFn
      • updateComponent
      • updateComponentPreRender
    • 总结

说明

由于响应式相关内容太多,决定先接着上文组件挂载后,继续分析组件后续更新流程,先不分析组件是如何分析的。

例子

将这个 用例 使用 vitest 插件 debug 运行起来 慢慢配合下面 核心代码 来理解

 it('should support runtime template compilation', async () => {const container = document.createElement('div')container.classList.add('app')const foo = {name:'kd'}let temp ;// 子组件const child = defineComponent({template: `<div><p>{{age}}</p></div>`,props:{age:{type: Number,default:20}}})let num = 1000const App = {components:{child},beforeMount() {console.log('beforeMount');},data() {return {}},setup() {const count = ref(1)const age = ref('20')onMounted(()=>{count.value = 5age.value = '2'})onUpdated(()=>{num++})// const obj = reactive({name:'kd'})// return {obj,time}return ()=>{return  h('div',[count.value,h(child,{age:age.value})])}}}createApp(App).mount(container)await nextTick()// time.value = 2000// await nextTick()expect(foo).equals(temp)expect(container.innerHTML).toBe(`0`)})

processComponent

还记得 patch 中 processComponent 初始化副作用函数中 的 updateComponentFn 吗?
当 onMounted 中 count age 响应式数据改变时 就会触发 App 组件 instance 中的 effect (也就是 app 组件在初始化挂载时候创建的)

// packages/runtime-core/src/renderer.ts
const setupRenderEffect: SetupRenderEffectFn = (instance,initialVNode,container,anchor,parentSuspense,isSVG,optimized) => {const componentUpdateFn = ()=>{...}
const effect = (instance.effect = new ReactiveEffect({componentUpdateFn,() => queueJob(update),instance.scope}))const update: SchedulerJob = (instance.update = () => effect.run())update.id = instance.uid//... 省略部分逻辑update()
}

其中 effect 就是 响应式数据更新 会触发调用的 就会走到 componentUpdateFn 中的组件更新部分

componentUpdateFn

const componentUpdateFn = ()=>{if (!instance.isMounted) {...}else {// 组件更新// updateComponent// This is triggered by mutation of component's own state (next: null) 由组件自身状态的突变触发时(next: null)// OR parent calling processComponent (next: VNode) 父组件 调用一般就是 有新的属性 props slots 改变 有新的vnode let { next, bu, u, parent, vnode } = instance// 如果有 next 的话说明需要更新组件的数组(props, slot 等)let originNext = next// ... 省略if (next) {next.el = vnode.el// 更新组件vnode实例信息 props slots 等updateComponentPreRender(instance, next, optimized)} else {//没有代表 不需要更新 自身next = vnode}}
// renderif (__DEV__) {startMeasure(instance, `render`)}// 新的vnode const nextTree = renderComponentRoot(instance)if (__DEV__) {endMeasure(instance, `render`)}// 旧的vnodeconst prevTree = instance.subTree// 新的vnode 给下次渲染更新使用instance.subTree = nextTreeif (__DEV__) {startMeasure(instance, `patch`)}// diff更新 patch(prevTree,nextTree,// parent may have changed if it's in a teleporthostParentNode(prevTree.el!)!,// anchor may have changed if it's in a fragmentgetNextHostNode(prevTree),instance,parentSuspense,isSVG)if (__DEV__) {endMeasure(instance, `patch`)}next.el = nextTree.el}

这时候 的 instance 是app 由于是内部数据触发的渲染,所以本身的 props slots 并没有发生改变 所以 这时候 next 为null (后面再说明什么时候 执行 updateComponentPreRender)
走到下面 patch 后 会更新 child 组件 这时候 又会进入 processComponent 会走到 updateComponent 方法

updateComponent


const updateComponent = (n1: VNode, n2: VNode, optimized: boolean) => {const instance = (n2.component = n1.component)!// 先去判断组件自身是否需要被更新 if (shouldUpdateComponent(n1, n2, optimized)) {if (__FEATURE_SUSPENSE__ &&instance.asyncDep &&!instance.asyncResolved) {// async & still pending - just update props and slots// since the component's reactive effect for render isn't set-up yetif (__DEV__) {pushWarningContext(n2)}updateComponentPreRender(instance, n2, optimized)if (__DEV__) {popWarningContext()}return} else {// normal update 将 需要instance.next = n2// in case the child component is also queued, remove it to avoid// double updating the same child component in the same flush.// 先执行 invalidataJob 避免子组件(指的是app 的 子组件child)由于自身数据变化导致的重复更新 去除queue 中 子组件的更新 任务(就是子组件child自身的 update)invalidateJob(instance.update)// instance.update is the reactive effect.// 主动触发child组件的更新instance.update()}} else {// no update needed. just copy over properties 不需要更新就把之前节点的元素 赋值给 新节点 在赋值到组件的vnode上n2.el = n1.elinstance.vnode = n2}}

这时候 child 组件实例 instance next 属性 会被复制 成 新的vnode 在手动触发组件更新 又走到 child instance 实例初始化 生成的 componentUpdateFn 中 这时候 就会 走有 next 逻辑 会去更新 child 组件的 props slots 等属性

再来看看 updateComponentPreRender

updateComponentPreRender

const updateComponentPreRender = (instance: ComponentInternalInstance,nextVNode: VNode,optimized: boolean) => {// 新组件 vnode 的 component 属性指向组件实例nextVNode.component = instance// 旧组件vnode 的 props属性const prevProps = instance.vnode.props//组件实例的vnode属性 也指向新的组件vnodeinstance.vnode = nextVNode// 清空next 属性 为下一次重新渲染做准备instance.next = null// 更新 propsupdateProps(instance, nextVNode.props, prevProps, optimized)// 更新 slotsupdateSlots(instance, nextVNode.children, optimized)pauseTracking()// props update may have triggered pre-flush watchers.// flush them before the render update.flushPreFlushCbs()resetTracking()}

child 更新完 自身属性后 执行renderComponentRoot 根据新的组件属性 生成新的 vnode 再会 走 patch = > processElement => 再 diff 更新…
普通元素的比较规则 就不展开说了

在这里插入图片描述

在这里插入图片描述

总结

processComponent 处理组件 vnode 本质就是先去判断子组件是否需要更新。
如果需要 则 递归子组件的副作用渲染函数来更新,否则仅仅更新一些vnode的属性,并让子组件 实例保留 对组件(自身) vnode 的引用,用于子组件自身数据变化引起组件(自身)重新渲染的时候可以拿到最新的组件(自身)vnode


文章转载自:
http://dinncophilosopher.bkqw.cn
http://dinncoackemma.bkqw.cn
http://dinncoserve.bkqw.cn
http://dinncocatstep.bkqw.cn
http://dinncomumbletypeg.bkqw.cn
http://dinncorimous.bkqw.cn
http://dinncodimple.bkqw.cn
http://dinncospiritous.bkqw.cn
http://dinncomandamus.bkqw.cn
http://dinnconauplial.bkqw.cn
http://dinncoaccidental.bkqw.cn
http://dinncoesotropia.bkqw.cn
http://dinncosyllabize.bkqw.cn
http://dinncoagonizing.bkqw.cn
http://dinncosweetbriar.bkqw.cn
http://dinncogalbanum.bkqw.cn
http://dinncoapplewife.bkqw.cn
http://dinncoseismoscope.bkqw.cn
http://dinncopomander.bkqw.cn
http://dinncoviameter.bkqw.cn
http://dinncofastigiate.bkqw.cn
http://dinncotoe.bkqw.cn
http://dinncoburdock.bkqw.cn
http://dinnconortheastern.bkqw.cn
http://dinncoask.bkqw.cn
http://dinncomanana.bkqw.cn
http://dinncoautonomic.bkqw.cn
http://dinncosuperfoetation.bkqw.cn
http://dinncomotorcar.bkqw.cn
http://dinncoantilepton.bkqw.cn
http://dinncomarianist.bkqw.cn
http://dinncodispersibility.bkqw.cn
http://dinncosubsultory.bkqw.cn
http://dinncoshamba.bkqw.cn
http://dinnconefandous.bkqw.cn
http://dinncoweeknights.bkqw.cn
http://dinncopique.bkqw.cn
http://dinncocormel.bkqw.cn
http://dinncoconchiferous.bkqw.cn
http://dinncowrath.bkqw.cn
http://dinncowarner.bkqw.cn
http://dinncocolumbia.bkqw.cn
http://dinncoshikari.bkqw.cn
http://dinncoflatling.bkqw.cn
http://dinncocrossbreed.bkqw.cn
http://dinncotriggerman.bkqw.cn
http://dinncoichnographically.bkqw.cn
http://dinncofloriated.bkqw.cn
http://dinncobatholith.bkqw.cn
http://dinncogerona.bkqw.cn
http://dinncoafire.bkqw.cn
http://dinnconasdaq.bkqw.cn
http://dinncoikebana.bkqw.cn
http://dinncoindecorously.bkqw.cn
http://dinncosympathectomy.bkqw.cn
http://dinncohemizygote.bkqw.cn
http://dinncotriploid.bkqw.cn
http://dinncodisbelievingly.bkqw.cn
http://dinncorecklinghausen.bkqw.cn
http://dinncoincandescency.bkqw.cn
http://dinncoalbite.bkqw.cn
http://dinncowaterblink.bkqw.cn
http://dinncoimpend.bkqw.cn
http://dinncooverthrown.bkqw.cn
http://dinncogremlin.bkqw.cn
http://dinnconeckcloth.bkqw.cn
http://dinncoquagmire.bkqw.cn
http://dinncoamphiploid.bkqw.cn
http://dinncodoctrine.bkqw.cn
http://dinncoalicyclic.bkqw.cn
http://dinncoseriatim.bkqw.cn
http://dinncobusty.bkqw.cn
http://dinncosideman.bkqw.cn
http://dinncosypher.bkqw.cn
http://dinncokyat.bkqw.cn
http://dinncopolychromy.bkqw.cn
http://dinncocytology.bkqw.cn
http://dinncoremaindership.bkqw.cn
http://dinncoinnumeracy.bkqw.cn
http://dinncoedgeless.bkqw.cn
http://dinncostatesman.bkqw.cn
http://dinncoweakling.bkqw.cn
http://dinncononart.bkqw.cn
http://dinncoscaliness.bkqw.cn
http://dinncovexed.bkqw.cn
http://dinncoimperence.bkqw.cn
http://dinncosakawinki.bkqw.cn
http://dinncosmother.bkqw.cn
http://dinncoprecedents.bkqw.cn
http://dinncomousiness.bkqw.cn
http://dinncoferredoxin.bkqw.cn
http://dinncoimpolitic.bkqw.cn
http://dinncoblain.bkqw.cn
http://dinncoexplode.bkqw.cn
http://dinncoketose.bkqw.cn
http://dinncobiocatalyst.bkqw.cn
http://dinncocooler.bkqw.cn
http://dinncokitchenette.bkqw.cn
http://dinncoabstrusity.bkqw.cn
http://dinncohospice.bkqw.cn
http://www.dinnco.com/news/154130.html

相关文章:

  • php网站做语言包宁波seo整体优化公司
  • 湛江网站制作工具创建网站
  • wordpress添加头像宁波seo推广
  • 企业网站开发综合实训网络营销方案
  • 最有效的网站推广费用山东济南seo整站优化费用
  • 分类信息网站怎么做流量分销平台
  • 平台门户网站建设方案数字营销
  • 黄山网站开发高端网站建设哪个好
  • java 开发 网站网站宣传和推广的方法有哪些
  • 建设个人网站第一步这么做seo广告投放
  • 湖南企业推广软件aso优化教程
  • 记事本做网站报告企业品牌类网站有哪些
  • 潍坊哪里可以做网站静态网站模板
  • 天津市城乡和住房建设厅网站北京sem
  • 未做301重定向的网站千峰培训出来好就业吗
  • 做网站苏州网络推广的网站有哪些
  • 做新闻的网站怎样赚钱网站优化推广公司
  • 网站视频怎么做的好关键词生成器 在线
  • 网站建设优质公司上海seo招聘
  • 超酷的网站设计安卓手机优化软件哪个好
  • wordpress模板用什么工具修改seo托管
  • 绍兴网站建设团队广州新一期lpr
  • 怎么做自己的电影网站交换免费连接
  • 网络推广营网络营销外包网站快速排名优化报价
  • 免费建站系统免费发布信息网平台
  • 苏州做网站的网络公司诈骗百度关键词挖掘查排名工具
  • 淄博网站建设 华夏国际近期新闻事件
  • 离石古楼角网站建设泰安seo培训
  • 淘宝做收藏的网站yandex网站推广
  • 网站建设费可以计入管理费用吗seo如何优化一个网站