render:h => h(App) ----render函数
转载其他博客
1 new Vue({
2
3 router,
4 store,
5 //components: { App } vue1.0的写法
6 render: h => h(App) vue2.0的写法
7 }).$mount('#app')
render函数是渲染一个视图,然后提供给el挂载,如果没有render那页面什么都不会出来
vue.2.0的渲染过程:
1.首先需要了解这是 es 6 的语法,表示 Vue 实例选项对象的 render 方法作为一个函数,接受传入的参数 h 函数,返回 h(App) 的函数调用结果。
2.其次,Vue 在创建 Vue 实例时,通过调用 render 方法来渲染实例的 DOM 树。
3.最后,Vue 在调用 render 方法时,会传入一个 createElement 函数作为参数,也就是这里的 h 的实参是 createElement 函数,然后 createElement 会以 APP 为参数进行调用,关于 createElement 函数的参数说明参见:Element-Arguments
render函数和自定义组件中temeplate作用类似,temeplate:"<h1>爱你</h1>"等价
于render(createElement){ return createElement("h1","爱你") }
//h为形参,可以嵌套使用但是都是写在h()中
render(h){
return h("h1",{
style:{color:'red'}
},"爱你")
}
渲染函数也可以直接放一个组件进去进行渲染
简写为render:h => h(zz)
//此时zz为另一个组件名字(需要进行注册操作)
vue.component("url",{
temeplate:"<h1>爱你</h1>"
//render(h){
//return h("h1",{
// style:{color:'red'}
//},"爱你")
}
})
结合一下官方文档的代码便可以很清晰的了解Vue2.0 render:h => h(App)的渲染过程。
[官方文档][1]:
1 render: function (createElement) {
2 return createElement(
3 'h' + this.level, // tag name 标签名称
4 this.$slots.default // 子组件中的阵列
5 )
6 }
render:h => h(App) ----render函数的更多相关文章
- 如何理解render: h => h(App)
学习vuejs的时候对这句代码不理解 new Vue({ el: '#app', router, store, i18n, render: h => h(App) }) 查找了有关资料,以下为结 ...
- vue-cli: render:h => h(App)是什么意思
import Vue from 'vue' import App from './App.vue' Vue.config.productionTip = false new Vue({ render: ...
- 关于Vue中的 render: h => h(App) 具体是什么含义?
render: h => h(App) 是下面内容的缩写: render: function (createElement) { return createElement(App); } 进一步 ...
- 解析vue2.0中render:h=>h(App)的具体意思
render:h=>h(App)是ES6中的箭头函数写法,等价于render:function(h){return h(App);}. 注意点:1.箭头函数中的this是 指向 包裹this所在 ...
- render:h => h(App) 是什么意思?
在学习vue.js时,使用vue-cli创建了一个vue项目,main.js文件中有一行代码不知道什么意思.在网上搜索得到如下解答: 参考一:https://www.cnblogs.com/longy ...
- Vue2.0 render:h => h(App)
new Vue({ router, store, //components: { App } vue1.0的写法 render: h => h(App) vue2.0的写法 }).$mount( ...
- Vue中render: h => h(App)的含义
// ES5 (function (h) { return h(App); }); // ES6 h => h(App); 官方文档 render: function (createElemen ...
- render: h => h(App) $mount 什么意思
初始一个vue.js项目时,常常发现main.js里有如下代码: new Vue({ render: h => h(App) }).$mount('#app') 这什么意思?那我自己做项目怎么改 ...
- Vue render: h => h(App) $mount
$mount()手动挂载 当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中: 假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载.例如: new Vue({ //el: ...
随机推荐
- javascript之Math对象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android studio 自动导入(全部)包 import (转)
原文: https://blog.csdn.net/buaaroid/article/details/44979629 1. Android studio 只有import单个包的快捷键:A ...
- 爬虫 selenium + phantomjs / chrome
selenium 模块 Web自动化测试工具, 可运行在浏览器,根据指定命令操作浏览器, 必须与第三方浏览器结合使用 安装 sudo pip3 install selenium phantomjs 浏 ...
- flask 学习(三)
继续flask的学习.尝试了使用程序context这一部分: 而在hello.py文档的旁边发现新出现了hello.pyc,看来运行过程中也被编译成字节码文件了,也不清楚是在哪个步骤的,留着后面研究. ...
- delphi怎么一次性动态删除(释放)数个动态创建的组件?
比如procedure TForm1.Button1Click(Sender: TObject);vari:Integer;lbl: TLabel;beginfor i:=1 to 3 dobegin ...
- java:solr
1.solr(数据导入solr自带数据库): ImportItemController.java: package com.solr.controller; import org.springfr ...
- django中使用mysql数据库
django连接mysql 安装MySQL 1 linux: apt install mysql-server apt install mysql-client mysql_secure_instal ...
- python基础知识(列表详解)
列表(list) 列表中可以存入整数.实数.布尔值.字符串.序列.对象 可变序列 列表 [] 元素间隔用 ,号分隔 列表的创建和删除 使用赋值运算符直接创建列表 listname = [元素1 ...
- photoshop人物美白教程:暗沉肤色提亮美白
内容提要:本篇photoshop人物美白教程的制作方法主要通过提取高光选区,配合滤色模式进行人物美白. ps美白教程在网络上搜索,会找到很多.本文介绍的PS人物美白方法,笔者看来是比较好的一种,主要是 ...
- PJzhang:微软出口管制条例
猫宁!!! 翻译:PJzhang 微软公司的技术,产品和服务受美国出口管理法规(EAR)的约束,由美国商务部工业与安全局(BIS)监督执行. 此外,财政部,国务院对其他与出口相关的技术和产品转让,交易 ...