網(wǎng)站首頁 編程語言 正文
可能會比較遺憾的說 React中并沒有vue中的 slot 插槽概念 不過 可以通過props.children 實現(xiàn)類似功能
我們先創(chuàng)建一個React項目
在src下創(chuàng)建目錄components 在下面創(chuàng)建一個dom.jsx組件
參考代碼如下
import React from "react"
export default class dom extends React.Component {
constructor(props){
super(props);
this.state = {
}
}
render(){
return (
<div>
<div>這里是dom組件</div>
<div>{ this.props.children }</div>
<div>元素結(jié)束</div>
</div>
)
}
}
這里 大家可以將this.props.children 理解為我們vue中的slot父組件插入的內(nèi)容就會放在這個位置
我們 App根組件編寫代碼如下
import React from "react"
import Dom from "./components/dom"
export default class App extends React.Component {
constructor(props){
super(props);
this.state = {
}
}
render(){
return (
<div>
<Dom>
<div>這是插槽內(nèi)容</div>
</Dom>
</div>
)
}
}
我們正常調(diào)用了剛才寫的dom組件 在中間插入了一個div 內(nèi)容為 這是插槽內(nèi)容
我們運行結(jié)果如下
可以看到 我們的內(nèi)容被成功插入在了 this.props.children 的位置
原文鏈接:https://blog.csdn.net/weixin_45966674/article/details/131468797
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-03-08 C語言設(shè)計前中后隊列實例代碼_C 語言
- 2022-10-23 Redis的過期鍵刪除策略原理說明_Redis
- 2022-06-08 換掉你的@RefreshScope吧
- 2022-04-06 用Python實現(xiàn)一個簡單的用戶系統(tǒng)_python
- 2022-12-14 Python桌面文件清理腳本分享_python
- 2022-04-08 MariaDB表表達式之公用表表達式(CTE)_mariadb
- 2022-06-30 PyTorch實現(xiàn)卷積神經(jīng)網(wǎng)絡的搭建詳解_python
- 2024-01-29 SpringBoot-yml文件的配置與讀取
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支