render: h => h(App) 是什么意思?
2017-10-13 11:11
459 查看
背景
在学习Vue.js时,使用
vue-cli创建了一个Vue项目,
main.js文件中有一行代码不知道是什么意思。在网上搜索了下,得到了答案,在此记录下。
main.js 文件内容
import Vue from 'vue' import App from './App.vue' new Vue({ el: '#app', render: h => h(App) })
h => h(App)这是什么,完全看不懂啊!!!So Google
解惑释疑
{ render: h => h(App); }
等价于
{ render: h => { return h(App); } }
等价于
{ render: function(h) { return h(App); } }
即:
{ render: function(createElement) { return createElement(App); } }
createElement 参数
看了 createElement 的官方文档,其实我还是不明白 createElement 的用法的。createElement 方法的参数有几个?各个参数的含义、类型是什么?
示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="app"></div> <script type="text/javascript" src="https://unpkg.com/vue"></script> <script type="text/javascript"> var app = new Vue({ el: '#app', // 提供一个在页面上已经存在的 DOM 元素作为 Vue 实例挂载目标 render: function (createElement) { return createElement('h2', 'Hello Vue!'); } }); </script> </body> </html>
相关文章推荐
- render: h => h(App) 是什么意思?
- web.xml <web-app>中xmlns="http://java.sun.com/xml/ns/j2ee"这一句是什么意思??
- vue2中 h => h(App)是个什么意思呢?
- new TypeToken<List<AppVersion>>(){}.getType()是什么意思
- web.xml中出现<servlet-name>default</servlet-name>是什么意思?
- <a href="#">链接</a>中的#是什么意思
- List<Map<String, Object>>是什么意思
- 网页源代码中的"<tr>"、"<td>"、"</tr>"和"</td>"各是什么意思?
- 在JSP中看到"<!--"和"-->"包起来的代码,又不是注释,这个是什么意思呢?
- struts配置中<result type="json"></reult>是什么意思 .
- VIM中的<C-r>=是什么意思
- PHP中的=>,->,=是什么意思?
- /dev/null 2>&1 什么意思
- <a href="javascript:;" id="button_qg_close"></a>表示什么意思?
- 语句:<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>是什么意思
- asp.net中,<%#%>,<%=%>和<%%>分别是什么意思,有什么区别
- <meta http-equiv="refresh" content="0; url=">是什么意思?
- <meta http-equiv="refresh" content="0; url=">什么意思?
- <column name="USERID" precision="10" scale="0" />什么意思???
- shell中的"2>&1"是什么意思?