vue2——new Vue({router,store, render: h => h(App) }).$mount(‘#app‘);分析

router

render: h => h(App) 是下面内容的缩写:

javascript 复制代码
render: function (createElement) {
    return createElement(App);
}

进一步缩写为(ES6 语法):

javascript 复制代码
render (createElement) {
    return createElement(App);
}

再进一步缩写为:

javascript 复制代码
render (h){
    return h(App);
}

按照 ES6 箭头函数的写法,就得到了:

javascript 复制代码
render: h => h(App);

It comes from the term "hyperscript", which is commonly used in many virtual-dom implementations. "Hyperscript" itself stands for "script that generates HTML structures" because HTML is the acronym for "hyper-text markup language".

它来自单词 hyperscript,这个单词通常用在 virtual-dom 的实现中。Hyperscript 本身是指

生成HTML 结构的 script 脚本,因为 HTML 是 hyper-text markup language 的缩写(超文本标记语言)

个人理解:createElement 函数是用来生成 HTML DOM 元素的,也就是上文中的 generate HTML structures,也就是 Hyperscript,这样作者才把 createElement 简写成 h。h是 Vue.js 里面的 createElement 函数,这个函数的作用就是生成一个 VNode节点,render 函数得到这个 VNode 节点之后,返回给 Vue.js 的 mount 函数,渲染成真实 DOM 节点,并挂载到根节点上。

相关推荐
独泪了无痕2 小时前
使用Fetch API 探索前后端数据交互
前端·http·交互设计
css趣多多2 小时前
别名路径的知识点
前端
靓仔建4 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
EnoYao4 小时前
我写了一个团队体检报告 Skill,把摸鱼的同事扒出来了😅
前端·javascript
梁正雄4 小时前
Python前端-2-css练习
前端·css·python
清汤饺子4 小时前
用 Cursor 半年了,效率还是没提升?是因为你没用对这 7 个功能
前端·后端·cursor
蓝莓味的口香糖4 小时前
【vue3】组件的批量全局注册
前端·javascript·vue.js
wefly20174 小时前
开发者效率神器!jsontop.cn一站式工具集,覆盖开发全流程高频需求
前端·后端·python·django·flask·前端开发工具·后端开发工具
独泪了无痕5 小时前
自动导入 AutoImport:告别手动引入依赖,优化Vue3开发体验
前端·vue.js·typescript
GDAL5 小时前
MANIFEST.in简介
linux·服务器·前端·python