Vue-js-modal: Passing data back from modal?

Created on 5 Jun 2020  路  2Comments  路  Source: euvl/vue-js-modal

Hi,

I'm having problems passing data back from a modal. With my use case, I couldn't find a suitable example in the documentation.

I'm using a custom .vue file which I show in the modal

<template>
    <div>
        <h1>This is modal</h1>
        <ul>
            <li v-for="item in items" :key="item.id" @click="select(item.id)">
                {{ item.id }}
            </li>
        </ul>
        <button @click="$emit('close')">Close</button>
    </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "../../vue-ext";

@Component
export default class TestModal extends Vue {
    @Prop() items: any[];

    async select(id: any) {
        console.log(id)
    }
}

Vue.component("test-modal", TestModal);
</script>

Here's how I'm opening the modal

async openItemSelect() {
    this.$modal.show(TestModal, 
        {
            items: [{id: 1}, {id: 2}]
        },
        {},
        { 
            "before-close": (event: any) => { console.log("before close"); }
        });
}

But I can't figure out how to tell the parent component what item was selected. Is there an example for something like this?

question answered

All 2 comments

You can use regular props down, events up, there is no reason why this shouldn't work as well, as the modal is a regular component.

Are you using any state management, you can send data there and the parent can get it quite easily.

And ofcourse you have the before-open and close event, these are not triggered while hte modal is active, you can use events or state for that.

Very good answer, thanks @ricky11 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

songoo picture songoo  路  4Comments

a3020 picture a3020  路  5Comments

dland512 picture dland512  路  4Comments

vesper8 picture vesper8  路  3Comments

ar53n picture ar53n  路  4Comments