render:h => h(App) 是什么意思?
在学习vue.js时,使用vue-cli创建了一个vue项目,main.js文件中有一行代码不知道什么意思。在网上搜索得到如下解答:
参考一:https://www.cnblogs.com/longying2008/p/6408753.html
参考二:https://www.cnblogs.com/whkl-m/p/6970859.html
main.js文件内容
import Vue from 'vue'
import App from './App' Vue.config.productionTip = false // 设置false,已阻止vue在启动时生成生产提示 /* eslint-disable no-new */
new Vue({
el:'#app',
render: h => h(App)
})
注:/* eslint-disable no-new */这不是一句注释,在js里面,new一个对象,需要赋值给某个值(变量),用Vue实例化时,不需要赋值给某值(变量),所以需要单独给配一条规则,给new Vue这行代码上面加这个注释,把这行代码规则的校验跳过,通过eslint-disable。是eslint的常用技巧之一。
言归正传:
render: h => h(App) 这是是一个箭头函数是肯定的,那对应的es5形式是怎样的呢???
如下:
{
render: h => h(App)
}
等价于:
{
render: h =>{
return h(App)
}
}
等价于:
{
render: function(h) {
return h(App);
}
}
即:
{
render: function(createElement) {
return createElement(App);
}
}
其实看了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) 是什么意思?的更多相关文章
- 如何理解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所在 ...
- 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: ...
- Vue2.0 render: h => h(App)的解释
render: h => h(App)是ES6的写法,其实就是如下内容的简写: render: function (createElement) { return createElement(A ...
随机推荐
- SaltStack生产案例-系统初始化
需求分析 一,系统初始化 1.1 关闭SELinux 1.2 关闭默认iptables 1.3 时间同步(配置NTP) 1.4 文件描述符(必备/etc/security/limmits.c ...
- 焦作网络赛L-Poor God Water【矩阵快速幂】
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- Oracle Schema Objects——Index
索引主要的作用是查询优化. Oracle Schema Objects 查看执行计划的权限:查看执行计划plustrace:set autotrace trace exp stat(SP2-0618. ...
- IntelliJ IDEA 插件
alibaba java coding guidelines 阿里巴巴Java编码指南插件支持. Mybatis-log-plugin 把 mybatis 输出的sql日志还原成完整的sql语句. ...
- Ubuntu18.04下安装比特币客户端
一.下载有两种安装方式:安装包和源码 二.安装1.通过安装包安装在https://bitcoin.org/en/download下载Windows,Mac OSX,Linux对应的安装包.安装过程比较 ...
- Day04 dom详解及js事件
day04 dom详解 DOM的基础 Document对象 Element对象 Node对象 innerHTML 事件处理 表单验证 上次课内容回顾: JS中ECMAScript用法: JS定义变 ...
- 百度领跑BAT all in O2O机遇大于挑战
近期一年O2O可谓是互联网领域最"炙手可热"的话题,似乎是个创业项目都要和O2O沾点关系.所以我们看到各种细分O2O模式层出不穷,并且,似乎外卖.洗车.租房等传统服务已经通 ...
- android Dialog官方demo
1.普通的Dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("今天 ...
- ROS 命令学习记录
#catkin_init_workspace //just get CMakeList.txt #catkin_make //增加了信文件夹 build和devel #Catkin_creat_pk ...
- 20165324_mypwd
20165324_mypwd 实验要求 实验要求 学习pwd命令 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 实现mypwd 测试mypwd 背景知识 文件存储结构 介绍文件 ...