網站首頁 編程語言 正文
可能會比較遺憾的說 React中并沒有vue中的 slot 插槽概念 不過 可以通過props.children 實現類似功能
我們先創建一個React項目
在src下創建目錄components 在下面創建一個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>元素結束</div>
</div>
)
}
}
這里 大家可以將this.props.children 理解為我們vue中的slot父組件插入的內容就會放在這個位置
我們 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>這是插槽內容</div>
</Dom>
</div>
)
}
}
我們正常調用了剛才寫的dom組件 在中間插入了一個div 內容為 這是插槽內容
我們運行結果如下
可以看到 我們的內容被成功插入在了 this.props.children 的位置
原文鏈接:https://blog.csdn.net/weixin_45966674/article/details/131468797
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-01-22 redis——緩存穿透、緩存擊穿、緩存雪崩、分布式鎖
- 2022-04-17 ajax請求成功后,設定一定時間過后執行關閉窗口命令
- 2022-03-08 使用C語言實現本地socke通訊的方法_C 語言
- 2022-04-09 Solr 檢索結果集List<SolrDocument> 轉換為指定業務對象總結
- 2022-03-14 flutter The argument type ‘String?‘ can‘t be assig
- 2022-09-18 GO語言原生實現文件上傳功能_Golang
- 2022-06-12 C語言?struct結構體超詳細講解_C 語言
- 2022-09-26 數據結構---圖、十字鏈表及其代碼實現
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支