0

I would like to add a dynamic child component to a parent component using Nativescript-Vue. For example:

<template>
    <MyParentComponent>
        <MyChildComponent :foo="foo"></MyChildComponent>
    </MyParentComponent>
<template>

<script>
    import MyParentComponent from './components/MyParentComponent';
    import MyChildComponent from './components/MyChildComponent';

    export default {
        components: {
            MyParentComponent,
            MyChildComponent
        },
        data: function(){
            return {
                foo: ''
            }
        }
    }
</script>

I think I need to define a slot in the parent component where the child component should be inserted, but I don't know how this should be done.

Any ideas?

1 Answer 1

5

In MyParentComponent's template you need to add a <slot /> tag, that's where Vue will insert the content.

Read more about slots, and what they can do in the Vue docs: https://v2.vuejs.org/v2/guide/components.html#Content-Distribution-with-Slots

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic. So it is exactly as it is in Vue.js. I don't know why my tests failed before, but now it works perfectly. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.