1π
β
Here is a sandbox example: link.
Try using slots
to achieve the same.
// App.vue (Parent component)
<template>
<div id="app">
<HelloWorld msg="Hello Vue in CodeSandbox!">
<random slot="random"/> // Component 2 being called inside Component 1
</HelloWorld>
</div>
</template>
<script>
import random from "./components/random";
import HelloWorld from "./components/HelloWorld";
export default {
name: "App",
components: {
HelloWorld,
random
}
};
</script>
// HelloWorld.vue (Component 1)
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<slot name="random"></slot>
</div>
</template>
<script>
export default {
name: "HelloWorld",
props: {
msg: String
}
};
</script>
// random.vue (Component 2)
<template>
<div>I am random</div>
</template>
π€priyanshu sinha
Source:stackexchange.com