How to close model from a button using vue.js ? Last Updated : 18 Jan, 2021 Comments Improve Suggest changes Like Article Like Report This article will tell us about how to close a modal from a button using vue.js. To close a modal using vue.js you can use the click event i.e. @click to trigger change in modal visibility. So, whenever the close button is pressed the @click method will trigger the function associated with the action ( here, hiding the modal ). SyntaxStep-1: Add @click="$emit('close')" property to the close button of the modal. <button type="button" class="close" @click="$emit('close')"> X </button> Step-2: In the component where modal is used add close modal and open modal properties in data data () { return { isModalVisible: false, }; }, methods: { showModal() { this.isModalVisible = true; }, closeModal() { this.isModalVisible = false; } }, };Sample Code:Creating the modal component JavaScript <!--Modal.vue--> <script> export default { name: 'modal', }; </script> <template> <transition name="modal-fade"> <div class="modal-backdrop"> <div class="modal" role="dialog" > <header class="modal-header" id="modalTitle" > <slot name="header"> Modal Header: GeeksforGeeks <button type="button" class="close" @click="$emit('close')" <!--Added the Click Event--> > X </button> </slot> </header> <section class="modal-body" id="modalDescription" > <slot name="body"> Closing modal using vue.js </slot> </section> </div> </div> </transition> </template> <style> .modal-backdrop { position: fixed; top: 0; bottom: 0; left: 0; right: 0; background-color: rgba(133, 226, 100, 0.427); display: flex; justify-content: center; align-items: center; } .modal { background: #eeeeee; width: 50%; height: 30%; box-shadow: 2px 2px 20px 1px; overflow-x: auto; display: flex; flex-direction: column; } .modal-header{ padding: 15px; display: flex; } .modal-header { border-bottom: 1px solid #eeeeee; font-size: 30px; color: #4AAE9B; justify-content: center; } .modal-body { position: relative; font-size: 30px; align-self: center; padding: 20px 10px; } .close { border: none; font-size: 30px; margin-left: 100px; cursor: pointer; font-weight: bold; color: #4AAE9B; background: transparent; } </style> Using the modal component in App.vue JavaScript <!--App.vue--> <script> import modal from './components/modal.vue'; export default { name: 'app', components: { modal, }, data () { return { isModalVisible: false, }; }, methods: { showModal() { this.isModalVisible = true; }, closeModal() { this.isModalVisible = false; } }, }; </script> <template> <div id="app"> <button type="button" class="btn" @click="showModal" > Open Modal </button> <modal v-show="isModalVisible" @close="closeModal" /> </div> </template> Output Comment More infoAdvertise with us Next Article How to close model from a button using vue.js ? S swapnil074 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2020 Vue.JS +1 More Similar Reads How to create a Popup Form using Vue.js & Tailwind CSS ? We'll create a simple popup form using Vue.js and Tailwind CSS. The form will allow users to input their email address and password. A button will open the form in the popup modal and users can submit the form or close it. Prerequisites HTMLTailwind CSSVue.jsApproachWe'll create a popup form using V 2 min read How to remove close button from jQuery UI dialog using jQuery ? In this article, we will learn how to remove the close button on the jQuery UI dialog using JavaScript, This can be achieved using the hide() method. jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. A dialog box is 2 min read How to expand button with animation on hover using Vue.js ? In this article, we will create a simple button using HTML and CSS. After that we will add some vue.js code to make animated button on mouse hover. For making the button animation first we create a button. On which we are going to apply hovering. HTML Button Code: HTML <!DOCTYPE html> <ht 2 min read How to Close a Tkinter Window With a Button? Prerequisites: Tkinter Python's Tkinter module offers the Button function to create a button in a Tkinter Window to execute any task once the button is clicked. The task can be assigned in the command parameter of Button() function. Given below are various methods by which this can be achieved. Meth 3 min read How to change the position of modal close button in bootstrap? The Modal component is a dialog box or a popup window that displays on top of the page. Modals can be used as alert windows as well as for accepting some input values. Example of a basic modal: For changing the position of the close button, we need to create a modal element. The below code will crea 4 min read How to Fire an Event When v-model Changes ? v-model is the two-way binding directive that mainly creates the connection between the input element and the data property. In this article, we will see how we can fire an event when the v-model directive is changed. We will see the two different approaches with the practical implementation in term 2 min read How to Toggle a Class in Vue.js ? In this article, we will use Vue.js component with a simple HTML template containing <div> and button elements. The goal is to toggle the presence of a CSS class on the <div> element when the button is clicked. By understanding the concepts of data binding, conditional rendering, and eve 3 min read How to Call a Vue.js Function on Page Load ? In this article, we will learn how to call a vue.js function on page load in VueJS. We will explore two different approaches with practical implementation in terms of examples and outputs. Table of Content Using mounted HookUsing created HookUsing mounted HookIn this approach, are using the mounted 2 min read Foundation CSS Close Button Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. This framework 3 min read How to use modal closing event in Twitter Bootstrap ? Bootstrap Modals offer a lightweight, multi-purpose JavaScript popup that's customizable and responsive. They can be used to display alert popups, videos, and images in a website. Bootstrap Modals are divided into three primary sections: header, body, and footer. Syntax: class | tabindex | role | ar 2 min read Like