vuejs关于函数式组件的探究
所以,在控制台里app1.exist 或app2.exist都可以控制是否显示字母.
<!DOCTYPE html>
<html lang='zh'>
<head>
<title>TEST</title>
</head>
<body>
<div id="app1">
<non-func :c_exist="exist"></non-func>
</div>
<div id="app2">
<is-func :c_exist="exist"></is-func>
</div>
<script src="https://cdn.staticfile.org/vue/2.1.6/vue.min.js"></script>
<script>
var render1 = function (h) {
var children = []
if (this.c_exist) {
children.push('Non-functional component')
}
return h('div', {}, children)
}
Vue.component('non-func',{
render :render1,
props:['c_exist'],
})
var app1 = new Vue({
el : '#app1',
data : {
exist:true,
},
})
// functional component
var render2 = function (h, ctx) {
console.log(ctx)
var children = []
if (ctx.data.attrs.c_exist) {
children.push('functional component')
}
return h('div', {}, children)
}
Vue.component('is-func',{
functional: true,
render :render2,
})
var app2 = new Vue({
el : '#app2',
data : {
exist:true,
},
})
</script>
</body>
</html>
这样也可以:
var render2 = function (h, ctx) {
console.log(ctx)
var children = []
if (ctx.props.c_exist) {
children.push('functional component')
}
return h('div', {}, children)
}
Vue.component('is-func',{
functional: true,
render :render2,
props:['c_exist'],
})
var app2 = new Vue({
el : '#app2',
data : {
exist:true,
},
})
vuejs关于函数式组件的探究的更多相关文章
- Vuejs函数式组件,你值得拥有(1)
函数式组件在React社区很流行使用,那么在vue里面我们要怎么用呢 下面会涉及到的知识点: 高阶函数.状态.实例.vue组件 什么是函数式组件 我们可以把函数式组件想像成组件里的一个函数,入参是渲染 ...
- 【vue】函数式组件
在 2.5.0 及以上版本中,如果你使用了单文件组件,那么基于模板的函数式组件可以这样声明: <template functional> <div class="cell& ...
- 渲染函数render和函数式组件
vnode对象 vnode对象包括(vnode并不是vue实例,而是vue实例中渲染函数render执行后生成的结果) this.tag = tag // 当前节点标签名 this.data = da ...
- react 中的无状态函数式组件
无状态函数式组件,顾名思义,无状态,也就是你无法使用State,也无法使用组件的生命周期方法,这就决定了函数组件都是展示性组件,接收Props,渲染DOM,而不关注其他逻辑. 其实无状态函数式组件也是 ...
- Vue函数式组件的应用
一.函数式组件和普通组件的区别 渲染快 没有实例,意味着没有(this) 没有生命周期(没有响应式数据) 二.组件函数的使用 1. 以局部组件为例,将组件标记为 functional=ture; 因为 ...
- 如何对 React 函数式组件进行优化
文章首发个人博客 前言 目的 本文只介绍函数式组件特有的性能优化方式,类组件和函数式组件都有的不介绍,比如 key 的使用.另外本文不详细的介绍 API 的使用,后面也许会写,其实想用好 hooks ...
- Vue.js 源码分析(三十) 高级应用 函数式组件 详解
函数式组件比较特殊,也非常的灵活,它可以根据传入该组件的内容动态的渲染成任意想要的节点,在一些比较复杂的高级组件里用到,比如Vue-router里的<router-view>组件就是一个函 ...
- React函数式组件使用Ref
目录: 简介 useRef forwardRef useImperativeHandle 回调Ref 简介 大家都知道React中的ref属性可以帮助我们获取子组件的实例或者Dom对象,进而对子组件进 ...
- Vue 函数式组件 functional
函数式组件 无状态 无法实例化 内部没有任何生命周期处理函数 轻量,渲染性能高,适合只依赖于外部数据传递而变化的组件(展示组件,无逻辑和状态修改) 在template标签里标明functional 只 ...
随机推荐
- MongDB配置方法
先下载安装包 安装 方法一:命令行启动 在 C:\MongoDB\Server\3.4目录下建立data文件夹, data里面建立db文件夹 bin目录下运行 mongod --dbpath C:\M ...
- Python的字典和JSON
Python的字典和JSON在表现形式上非常相似 #这是Python中的一个字典 dic = { 'str': 'this is a string', 'list': [1, 2, 'a', 'b'] ...
- 原来你是这样的Promise
1. Promise简介 promise是异步编程的一种解决方案,它出现的初衷是为了解决回调地狱的问题. 打个比方,我需要: --(延迟1s)--> 输出1 --(延迟2s)--> 输出2 ...
- WPF 自定义TreeView控件样式,仿QQ联系人列表
一.前言 TreeView控件在项目中使用比较频繁,普通的TreeView并不能满足我们的需求.因此我们需要滴对TreeView进行改造.下面的内容将介绍仿QQ联系人TreeView样式及TreeVi ...
- [LeetCode] Maximum Width of Binary Tree 二叉树的最大宽度
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...
- [LeetCode] Kill Process 结束进程
Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...
- [LeetCode] Contiguous Array 邻近数组
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. ...
- C++primer学习——左值和右值
定义: 左值:用的是对象的身份 右值:用的是对象的值(内存) decltype: 当其作用于表达式时,如果求值结果是左值,那么返回一个引用 如果求值结果是右值,那么返回正常 int*p; declty ...
- hdu 5534(dp)
Input The first line contains an integer T indicating the total number of test cases. Each test case ...
- Linux查看Tomcat是否多次重启命令
1.查看命令 ps -ef|grep apache-tomcat-9090|grep -v grep|awk '{print $2}' 如果存在两个端口则多次重启, 2.停掉命令: kill -9 ...