vue.js - vue中如何使用children?
问题描述
我在我的不同项目中使用React.js
和Vue.js
作为前端。
在 React 中,我可以MyComponent
像这样包装模板。
<MyComponent>
<div>Here</div>
</MyComponent>
在 MyComponent 文件中
const MyComponent = ({children}) {
return (
<div className="my-component">{children}</div>
)
}
我如何在Vue.js
???中使用这种简单的技术?
解决方案
您将需要使用Slots。
这是取自 vuejs doc 的示例
组件模板:
<a :href="url">
<slot></slot>
</a>
编码:
<navigation-link url="/profile">
Your Profile
</navigation-link>
<slot></slot>
将被组件标签内的内容替换。它将呈现为:
<a url="/profile">
Your Profile
</a>
推荐阅读
- python-3.x - 有没有办法在 for 循环中创建带有单独变量的条目(以便稍后访问)?
- javascript - 'this' 如何在 Javascript 中创建对象的构造函数中工作
- javascript - 渲染屏幕很困难
- mysql - PGLOADER 没有数据导入 - 没有错误(mysql 到 postgres 迁移)
- java - MySupportMapFragment 不根据谷歌地图 Android 显示位置名称
- mysql - 有没有办法使用 MySQL 触发器复制表中的记录,但在插入之前修改数据?
- r - 使用 0 和 0.00% 值提取 Dataframe 中的所有行
- android - 独立于其他活动运行 android 应用程序特定活动
- eclipse - 如何更改 Eclipse 的“Packages”选项卡的背景颜色
- javascript - 如何在 laravel 中管理不同刀片上的计数器?