1

I use VueJS on one page. It's just imported from CDN so I can't use bootstrap-vue.

I'm trying to show and hide modal when showModal data is true.

So far it works but it does not show the gray overlay surrounding the modal. How can I do that? It's Bootstrap 5.

 <div id="exampleModalLong" tabindex="-1" aria-labelledby="exampleModalLongTitle" class="modal fade"
         :class="showModal ? 'show' : ''" :style="{display: showModal ? 'block' : 'none'}" :aria-modal="showModal ? 'true' : ''"
         :role="showModal ? 'dialog' : ''">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div style="width: 400px;">
                        <form>

                            <div id="div_id_api_secret_key" class="form-group">
                                <div v-for="field in journeySourceApp.details.fields">
                                    <label :for="field.name" class=" requiredField">
                                        [[field.name]]<span class="asteriskField">*</span> </label>
                                    <div class="">
                                        <input type="text" :name="field.name" v-model="authorizeAppForm[field.name]"
                                               class="textinput textInput form-control" required=""
                                               id="id_api_secret_key">
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                        <button type="button" class="btn btn-primary" @click="createAppInstance">Save</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
Milano
  • 18,048
  • 37
  • 153
  • 353
  • 1
    FYI you can use `bootstrap-vue` over a [CDN](https://bootstrap-vue.org/docs#browser) – Hiws Mar 14 '22 at 14:07
  • If you don't post your ```JS code```, we could not test it in our development environment. – hamid-davodi Mar 14 '22 at 14:13
  • Please show the js code too. It works like this: https://stackoverflow.com/questions/42890385/open-bootstrap-modal-with-vue-js-2-0/66534012#66534012 – Carol Skelly Mar 14 '22 at 14:52

1 Answers1

0

It goes like this

<button class="btn btn-primary" v-on:click="newAddressModal.show()">
    Show Modal
</button>
<div class="modal fade" id="newModal" ref="newModal">
    <div class="modal-dialog">
        <div class="modal-content p-3">
            <div class="modal-header">
                <h3>Header</h3>
            </div>
        </div>
        <div class="modal-body">
            body
        </div>
    </div>
</div>
<script>
import { Modal } from 'bootstrap';
export default {
    data(){
        newModal : null
    },
    mounted(){
        this.newModal = new Modal(this.$refs.nweModal);
    }
}

Works on vue 3 bootstrap 5

Venkatesh A
  • 1,875
  • 1
  • 19
  • 23