vue functional函数式组件
2024-08-31 09:39:49
第1种写法
test.vue
<template functional>
<div class="test">
{{props.test.name}}
</div>
</template>
<script>
export default {
props: {
test: Object,
default: () => ({})
}
}
</script>
父组件 index.vue
<template>
<div>
<test :test="{name: 'vue'}"></test>
</div>
</template>
<script>
import test from './test'
export default {
components: {
test
}
</script>
第2种写法
test.js
import Vue from 'vue'
Vue.component('test', {
functional: true,
props: {
test: {
type: Object,
required: true
}
},
render: function (createElement, context) {
return createElement(
'div',
{
attrs: {
class: 'test'
}
},
[context.props.test.name]
)
}
})
父组件 index.vue
<template>
<div>
<test :test="{name: 'vue'}"></test>
</div>
</template>
<script>
import './test.js'
</script>
最新文章
- 一个技术汪的开源梦 —— 基于 .Net Core 的组件 Nuget 包制作 &; 发布
- 50. 树的子结构[subtree structure in tree]
- JSP内置对象及常用方法
- Notepad++的xml文本格式化
- 锋利的js之妈妈再也不用担心我找错钱了
- HDU 1016 Prime Ring Problem(经典DFS+回溯)
- Linux是怎么启动的
- 对DTU系统结构的重新思考
- 基于visual Studio2013解决C语言竞赛题之1068指针数组
- C#中的Virtual、Override和new关键词理解
- 修复 Ubuntu 14.04 的系统设置残缺问题
- hadoop中setup,cleanup,run和context讲解
- Pytorch入门实例:mnist分类训练
- struts2框架之文件下载(参考第三天学习笔记)
- docker自动重启容器
- java JDK安装教程
- Row_number 详解
- bzoj3839【Pa2013】Działka
- openerp在ubuntu中查看日志
- 《从零开始学Swift》学习笔记(Day54)——抛出错误
热门文章
- Docker - 解决同步容器与主机时间报错:Error response from daemon: Error processing tar file(exit status 1): invalid symlink ";/usr/share/zoneinfo/UTC"; ->; ";../usr/share/zoneinfo/Asia/Shanghai";
- nginx&;http 第三章 ngx http ngx_http_process_request_headers
- orphan sockets
- leetcode Reverse Nodes in k-Group翻转链表K个一组
- 基于FFmpeg的Dxva2硬解码及Direct3D显示(四)
- MyBatis 使用手册
- Stream流的这些操作,你得知道,对你工作有很大帮助
- 实在是秒啊,我还从来没见过把Spring之AOP讲的这么通俗易懂的,安排!
- 用过MindManager后才知道思维导图原来这么简单
- 详解CorelDRAW中刻刀工具的具体运用