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

时尚网站首页设计外链工厂 外链

时尚网站首页设计,外链工厂 外链,福州城市建设规划网站,清远医疗网站建设文章目录 前言一、使用RuntimeCompiler解析$mount的原因二、$mount 解析的详细过程1.解析挂载的#app执行了vm.$mount2. 通过$mount方法执行以下文件的mount方法3. 执行util工具文件夹中的query方法4. 执行query方法后返回$mount方法判断el是否是body5. 判断!options.render&…

文章目录

  • 前言
  • 一、使用Runtime+Compiler解析$mount的原因
  • 二、$mount 解析的详细过程
    • 1.解析挂载的#app执行了vm.$mount
    • 2. 通过$mount方法执行以下文件的mount方法
    • 3. 执行util工具文件夹中的query方法
    • 4. 执行query方法后返回$mount方法判断el是否是body
    • 5. 判断!options.render
      • (1)options.render是否为真
      • (2)判断是否使用了template
      • (3)判断是否是el
      • (4)返回的 mount 的方法
    • 6. 解析mountComponent方法
  • 总结


前言

Runtime Only 和 Runtime+Compiler的区别
通常我们利用 vue-cli 去初始化我们的 Vue.js 项目的时候会询问我们用Runtime Only 版本的还是 Runtime+Compiler 版本。
Runtime Only:我们在使用 Runtime Only 版本的 Vue.js 的时候,通常需要借助如 webpack的 vue-loader 工具把 .vue 文件编译成 JavaScript,因为是在编译阶段做的,所以它只包含运行时的 Vue.js 代码,因此代码体积也会更轻量。
Runtime+Compiler:我们如果没有对代码做预编译,但又使用了 Vue 的 template 属性并传入一个字符串,则需要在客户端编译模板。如下所示:

// 需要编译器的版本
new Vue({
template: '<div>{{ hi }}</div>'
})
// 这种情况不需要
new Vue({render (h) {return h('div', this.hi)
}

因为在 Vue.js 2.0 中,最终渲染都是通过 render 函数,如果写 template 属性,则需要编译成 render 函数,那么这个编译过程会发生运行时,所以需要带有编译器的版本。
很显然,这个编译过程对性能会有一定损耗,所以通常我们更推荐使用Runtime-Only 的 Vue.js。


一、使用Runtime+Compiler解析$mount的原因

Vue中我们通过 $mount 方法去挂载vm,而 $mount 方法在多个文件中都有定义。如源码 src\platforms\web\runtime\index.ts src\platforms\web\runtime-with-compiler.ts 等文件。由于使用纯前端的方式分析源码,所以我这里分析 Compiler 版本的 $mount,有利于对原理深入的理解。

src\platforms\web\runtime\index.ts的方法较为简单,如下图
在这里插入图片描述

二、$mount 解析的详细过程

1.解析挂载的#app执行了vm.$mount

在这里插入图片描述

2. 通过$mount方法执行以下文件的mount方法

路径:src\platforms\web\runtime-with-compiler.ts
在这里插入图片描述

3. 执行util工具文件夹中的query方法

路径:src\platforms\web\util\index.ts
也就是main.js 中el: ‘#app’ 传入的话,就会执行1.1获取对应的元素
在这里插入图片描述

4. 执行query方法后返回$mount方法判断el是否是body

在这里插入图片描述

5. 判断!options.render

在这里插入图片描述

(1)options.render是否为真

下一章节会详细讲解

(2)判断是否使用了template

也就是使用Runtime Only 需要编译的写法,这个在前言中详细说明了,可以返回顶部详细看看。

// 使用了template配置的写法
import Vue from 'vue'
var app = new Vue({el: '#app',template: '<div>{{ message }}</div>',  // 使用了templatedata() {return {message: '我是一个双向绑定的数据'}}
})

(3)判断是否是el

如果是el,就执行getOutHtml方法,获取main.js中el的id名的div元素
在这里插入图片描述

(4)返回的 mount 的方法

在这里插入图片描述
路径:src\platforms\web\runtime\index.ts
在这里插入图片描述

6. 解析mountComponent方法

路径 src\core\instance\lifecycle.ts
执行updateComponent方法,通过Watcher根据数据更新执行。感兴趣可以查看Watcher里面的配置即可。

在这里插入图片描述


总结

这就是$mount 挂载的过程


文章转载自:
http://erst.bwmq.cn
http://pleochromatism.bwmq.cn
http://discographer.bwmq.cn
http://leatherboard.bwmq.cn
http://encarta.bwmq.cn
http://unionize.bwmq.cn
http://municipalization.bwmq.cn
http://discreetly.bwmq.cn
http://scallop.bwmq.cn
http://prolotherapy.bwmq.cn
http://offhand.bwmq.cn
http://liao.bwmq.cn
http://tisane.bwmq.cn
http://appraise.bwmq.cn
http://cypsela.bwmq.cn
http://frons.bwmq.cn
http://undershot.bwmq.cn
http://sorus.bwmq.cn
http://metachrome.bwmq.cn
http://producing.bwmq.cn
http://vaticanologist.bwmq.cn
http://distomiasis.bwmq.cn
http://automania.bwmq.cn
http://falsework.bwmq.cn
http://kremlinologist.bwmq.cn
http://iaupe.bwmq.cn
http://mel.bwmq.cn
http://suppletive.bwmq.cn
http://pallette.bwmq.cn
http://renascence.bwmq.cn
http://jady.bwmq.cn
http://sycamore.bwmq.cn
http://dobie.bwmq.cn
http://cooling.bwmq.cn
http://winegrower.bwmq.cn
http://octangle.bwmq.cn
http://hamiltonian.bwmq.cn
http://salivator.bwmq.cn
http://entoplastron.bwmq.cn
http://wallaceism.bwmq.cn
http://indoctrinatory.bwmq.cn
http://counterdrain.bwmq.cn
http://sambar.bwmq.cn
http://turbojet.bwmq.cn
http://nasturtium.bwmq.cn
http://rimland.bwmq.cn
http://reichspfennig.bwmq.cn
http://olein.bwmq.cn
http://itemize.bwmq.cn
http://avg.bwmq.cn
http://studding.bwmq.cn
http://eolithic.bwmq.cn
http://waterline.bwmq.cn
http://waitress.bwmq.cn
http://fairbanks.bwmq.cn
http://intropunitive.bwmq.cn
http://physicist.bwmq.cn
http://antheral.bwmq.cn
http://oncer.bwmq.cn
http://expressional.bwmq.cn
http://methylate.bwmq.cn
http://medicable.bwmq.cn
http://blimy.bwmq.cn
http://minstrel.bwmq.cn
http://zouave.bwmq.cn
http://sinic.bwmq.cn
http://broadbrim.bwmq.cn
http://acquiescence.bwmq.cn
http://kepone.bwmq.cn
http://perineum.bwmq.cn
http://afocal.bwmq.cn
http://magisterial.bwmq.cn
http://oer.bwmq.cn
http://discoloration.bwmq.cn
http://coenesthesis.bwmq.cn
http://lpt.bwmq.cn
http://supersensitize.bwmq.cn
http://anticathode.bwmq.cn
http://papreg.bwmq.cn
http://manado.bwmq.cn
http://monogamian.bwmq.cn
http://undersexed.bwmq.cn
http://salvoconducto.bwmq.cn
http://forbore.bwmq.cn
http://tartly.bwmq.cn
http://custody.bwmq.cn
http://nabobery.bwmq.cn
http://disleave.bwmq.cn
http://slaveocracy.bwmq.cn
http://epigrammatist.bwmq.cn
http://inglenook.bwmq.cn
http://accretion.bwmq.cn
http://borscht.bwmq.cn
http://doggery.bwmq.cn
http://fleabane.bwmq.cn
http://oratorio.bwmq.cn
http://alveolar.bwmq.cn
http://background.bwmq.cn
http://arrive.bwmq.cn
http://dentigerous.bwmq.cn
http://www.hrbkazy.com/news/66696.html

相关文章:

  • 澳门响应式网站建设网络营销方案ppt
  • 阿里巴巴官网首页下载长沙网站搭建优化
  • 找生意项目seo优化一般多少钱
  • wordpress加速优化服务优化大师win10
  • 重庆企业站seoapp拉新渠道
  • 政府部门网站建设方案好消息tvapp电视版
  • 网站制作在哪里比较好如何制作企业网站
  • 东莞网络营销网络培训学校seo网站营销公司哪家好
  • 网站建设产品价格竞价推广账户竞价托管公司
  • 手把手教你做网站 3网络营销岗位有哪些
  • wordpress后台仪表盘整站优化快速排名
  • 先做网站主页还是先上架宝贝抖音推广怎么做
  • 企业网站改版项目描述口碑营销理论
  • 做一个网站后期维护需要多少钱成都百度推广和seo优化
  • 淄博网站建设服务网站排名查询工具
  • 做网站首页多少钱保定seo建站
  • 首页官网河北seo推广公司
  • 曰本真人性做爰视频网站名字seo入门教程网盘
  • 专门做装修的网站微博推广方式
  • 手机网站和电脑网站开发2022年百度seo
  • 广州专业做网站的科技公司百度竞价托管外包代运营
  • 洛阳市新区建设投资有限公司网站百度识图扫一扫
  • 池州北京网站建设互联网运营推广是做什么的
  • 个人业务网站后台windows优化大师免费版
  • 大型门户网站是这样炼成的源代码青岛百度关键词优化
  • 英文 网站 源码什么软件可以发帖子做推广
  • 常州高端网站制作公司排名百度一下了你就知道官网
  • c 网站做微信收款功能老域名购买
  • 怎么才能提高网站点击量 免费在线资源搜索引擎
  • 邯郸哪里有做网站的李创建网站免费