Hey there! I'm looking to enclose the content of a component with a specific HTML tag, let's say button
for this scenario.
I have a function that dynamically returns a value which I use as a prop. Based on that, I want to wrap the component's content.
I am aware that I could achieve this by doing something like
<button><compA/></button>
, but that doesn't work for me because it would require changing it in multiple places.
This is what I expect:
<button><div>press me i'm button</div></button>
<div>don't wrap me with button leave me as it is</div>
Note: Setting :wrappwithbutton=""
to true
for the first case and false
for the second case.
const localComponent = {
name:'first-comp',
template:`<div> {{text}}</div>`,
props:['wrappwithbutton','text'],
}
const app = new Vue({
el:'#app',
name:'app',
components:{'first-comp':localComponent},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<first-comp :wrappwithbutton="true" text="press me i'm button"></first-comp>
<br/>
<hr/>
<br/>
<first-comp :wrappwithbutton="false" text="don't wrap me with button leave me as it is"></first-comp>
</div>