javascript - How can I run a statement when modal close on vue? - Stack Overflow

My vue ponent like this :<template>...<b-modal ref="modal" id="modalInvoice&quo

My vue ponent like this :

<template>
    ...
    <b-modal ref="modal" id="modalInvoice" size="lg"  title="Invoice">
        <Invoice/>
        <div slot="modal-footer" class="w-100"> 
            <b-btn size="sm" class="float-right" variant="warning" @click="show=false">
                <i class="fa fa-print"></i> Print
            </b-btn>
        </div>
    </b-modal>

    ...
        <b-btn variant="warning" class="btn-square mt-2" v-b-modal.modalInvoice @click="checkout()"><i class="fa fa-credit-card-alt"></i>Checkout</b-btn>
    ...
</template>
<script>
    ...
    export default {
        ...
        mounted() {
            $(this.$refs.modal).on('hidden.bs.modal', () => {
                console.log('close modal')
            })
        },
    }
</script>

I try like that. So I try using ref="modal" and mounted. But it does not works. If modal close, the console.log is not show

How can I solve this problem?

My vue ponent like this :

<template>
    ...
    <b-modal ref="modal" id="modalInvoice" size="lg"  title="Invoice">
        <Invoice/>
        <div slot="modal-footer" class="w-100"> 
            <b-btn size="sm" class="float-right" variant="warning" @click="show=false">
                <i class="fa fa-print"></i> Print
            </b-btn>
        </div>
    </b-modal>

    ...
        <b-btn variant="warning" class="btn-square mt-2" v-b-modal.modalInvoice @click="checkout()"><i class="fa fa-credit-card-alt"></i>Checkout</b-btn>
    ...
</template>
<script>
    ...
    export default {
        ...
        mounted() {
            $(this.$refs.modal).on('hidden.bs.modal', () => {
                console.log('close modal')
            })
        },
    }
</script>

I try like that. So I try using ref="modal" and mounted. But it does not works. If modal close, the console.log is not show

How can I solve this problem?

Share Improve this question asked Sep 11, 2018 at 7:32 moses tohmoses toh 13.2k81 gold badges265 silver badges459 bronze badges 2
  • Instead of @click="show=false" add a function that changes show property and does what you need? – dziraf Commented Sep 11, 2018 at 7:36
  • Could you provide us some more information? 1. B-modal is your ponent or is it from some framework or library? 2. Are you sure that the event is emitted properly so the error is only in catching the event? 3. Are you sure that it is the b-modal ponent that emits the event (not the button or the invoice)? – Máté Wiszt Commented Sep 11, 2018 at 7:41
Add a ment  | 

1 Answer 1

Reset to default 6

Add an event listener on the modal ponent:

<b-modal ref="modal" id="modalInvoice" size="lg"  title="Invoice" @hidden="onHidden">
    <Invoice/>
    <div slot="modal-footer" class="w-100"> 
        <b-btn size="sm" class="float-right" variant="warning" @click="show=false">
            <i class="fa fa-print"></i> Print
        </b-btn>
    </div>
</b-modal>

methods: {
  onHidden (e) {
    console.log('the modal was hidden')
  }
}

All the events are listed under the Component Reference section.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744348724a4569846.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信