//子组件
const Haizi = ({ children }) => {
console.log(children);
return (
<>
{children.foot}
{children.content}
{children.herder}
{children.scope(Math.random())}
</>)
}
//父组件
const RIndex = () => {
const handleclick = (value) => {
console.log(value);
}
return (
<Haizi>
{{
herder: <div>我是herder</div>,
content: <div>我是content</div>,
foot: <div>我是foot</div>,
scope: value => <button onClick={() => handleclick(value)}>作用域插槽</button>
}}
</Haizi>
)
}
export default RIndex
12-28
325
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-10
1372
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-03
123
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交