Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VueJs: Using component inside another component

I'm trying to make use of the main component inside another with pre-defined properties.

Here's what I'm trying to achieve, but I'm just getting an empty div as a result.

<template>
    <call-dialog-link
        :id="id"
        :url=url"
        message="Are you sure you wish to remove this record?"
        label="Remove"
        css-classes="alert"
    ></call-dialog-link>
</template>
<script>
    import CallDialogLink from './CallDialogLink.vue';
    export default {
        props: {
            id: {
                type: String,
                required: true
            },
            url: {
                type: String,
                required: true
            }
        },
        components: {
            'call-dialog-link': CallDialogLink
        }
    };
</script>

Here's the CallDialogLink component

<template>
    <span class="clickAble" :class="cssClasses" v-text="label" @click="clicked()"></span>
</template>
<script>
    export default {
        props: {
            id: {
                type: String,
                required: true
            },
            url: {
                type: String,
                required: true
            },
            message: {
                type: String,
                required: true
            },
            label: {
                type: String,
                required: true
            },
            cssClasses: {
                type: String,
                required: false
            }
        },
        mounted() {
            window.EventHandler.listen('remove-dialog-' + this.id + '-called', (data) => {
                window.location.reload(true);
            });
        },
        methods: {
            clicked() {
                window.EventHandler.fire('top-confirm', {
                    id: 'remove-dialog-' + this.id,
                    message: this.message,
                    url: this.url
                });
            }
        }
    };
</script>

Any idea what I'm doing wrong?

like image 980
Sebastian Sulinski Avatar asked Feb 16 '17 09:02

Sebastian Sulinski


People also ask

How do you put a component inside another component in Vue?

You need to create your portfolio component first e.g. in src/components/Projects/Portfolio. vue and then import it inside the script tag within your Landing.

How do I use imported components at Vue?

STEP 01: First, Import the Child Component into the Parent Component inside script tag but above export default function declaration. STEP 02: Then, Register the Child Component inside the Parent Component by adding it to components object. STEP 03: Finally, Use the Child Component in the Parent Component Template.


1 Answers

I believe there is typo in your code.

<template>
    <call-dialog-link
        :id="id"
        :url="url" // didn't open the double quote here
        message="Are you sure you wish to remove this record?"
        label="Remove"
        css-classes="alert"
    ></call-dialog-link>
</template>
like image 190
Srinivas Damam Avatar answered Oct 03 '22 11:10

Srinivas Damam