Vue中 乍一看让人懵逼的代码

你。 提交于 2020-02-28 10:39:57

render: h => h(App)

出自 vue cli 构建的 main.js 文件中,首先看看各个版本的写法:

components: { App } // vue1.0的写法
render: h => h(App)  //  vue2.0的写法

再来看看官方解释:接收一个方法,作为第一参数,这是关键点

在这里插入图片描述

查资料得出,ES6语法,表示 Vue 实例选项对象的 render 方法作为一个函数,接受传入的参数 h 函数,返回 h(App) 的函数调用结果。

那么转换成代码大概就是这个样子

function render(h){
	return h("yes");
}

function h(arg1){
	console.log(arg1)
}

render(h) // => 输出 yes

其中h的理解 (根据Vue. js作者Even You的回复,h的含义如下:)

It comes from the term “hyperscript”, which is commonly used in many virtual-dom
implementations. “Hyperscript” itself stands for "script thatgenerates HTML structures
HTML is the acronym for “hvper-text markup language”.
它来自单词hyperscript,这个单词通常用在virtual-dom的实现中。Hyperscript本身是指
生成HTML结构的script脚本因为HTML是hyper-text markup language的缩写(超文本标

main.js中的 $mount

C:\Users\wuyuwei\AppData\Local\YNote\data\qq74BCA8BF64E0BB769C94E71C18E7F5DC\a6e6a88d3f7148618d2287cb91976fa7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!