I want to switch between two single file component in vuejs, i don't how to use attach and detach functions
-
I am very new to vuejs, just want to know how we can switch between two single file component within a single parent.RAHIL KHAN– RAHIL KHAN2018-06-21 09:45:28 +00:00Commented Jun 21, 2018 at 9:45
-
Possible duplicate of How to mount dynamically single file component in Vue.jsJP. Aulet– JP. Aulet2018-06-21 10:02:11 +00:00Commented Jun 21, 2018 at 10:02
Add a comment
|
1 Answer
You can use the component which is a built in component provided by vue.
HTML
<div id="app">
<h3>Parent component</h3>
<button @click="current= 'ComponentA'">Show component A</button>
<button @click="current= 'ComponentB'">Show component B</button>
<component :is="current"></component>
</div>
script
const ComponentA ={
template:"<h4>This is component A</h4>"
}
const ComponentB ={
template:"<h4>This is component B</h4>"
}
new Vue({
el:'#app',
data:{
current: "ComponentA"
},
components:{
ComponentA,
ComponentB
},
})
Here is the fiddle