Reputation: 549
I am using React.js
and Vue.js
for frontend in my different projects.
In React, I am able to wrap templates with MyComponent
like this.
<MyComponent>
<div>Here</div>
</MyComponent>
And in MyComponent file
const MyComponent = ({children}) {
return (
<div className="my-component">{children}</div>
)
}
How can I use this simple technique in Vue.js
???
Upvotes: 3
Views: 379
Reputation: 3270
You will want to use Slots.
Here is an example taken from vuejs doc
Component template:
<a :href="url">
<slot></slot>
</a>
The code:
<navigation-link url="/profile">
Your Profile
</navigation-link>
<slot></slot>
will be replaced by what's inside the component tags. It will be rendered as:
<a url="/profile">
Your Profile
</a>
Upvotes: 3