PrefaceThe dialog box is a very common component and is used in many places. Generally, we can use the built-in alert to pop up the dialog box, but what if it is a designed diagram? So we need to write a dialog box ourselves. Let's take a look at the detailed implementation process. RenderingIn the above screenshot, the red border indicates that the "text, icon or image" is the editable part. Example Code1. Create a pop-up component quitDialog.vue component <template> <transition-group name='fade'> <!-- Exit pop-up window--> <div class="quit_dialog" key="1" @click="isQuit = false" v-if="isQuit" @touchmove.prevent> </div> <div class="quit_box" v-show="isQuit" key="2"> <img :src="imgUrl" :alt="imgLoadTip"> <div class="quit_title">{{title}}</div> <p>{{content}}</p> <button class="quit_btn" @click="leftClick">{{btnText}}</button> <button class="quit_close" @click="rightClick">{{rightText}}</button> </div> </transition-group> </template> <script> export default { name: 'Popup', data () { return { isQuit: false, imgUrl: '', title: '', content: '', btnText: '', rightText: '' } }, methods: { leftClick () { this.leftBtn() this.isQuit = false }, rightClick () { this.rightBtn() this.isQuit = false } } } </script> <style lang="scss" scoped> // Exit pop-up window.fade-enter, .fade-leave-active { opacity: 0; } .fade-enter-active, .fade-leave-active { transition: opacity 0.35s; } // Global pop-up window.quit_dialog { background: rgba(0,0,0,.5); position: fixed; top: 0; left: 0; height: 100%; width: 100%; z-index: 10000; } .quit_box { width: 700px; background: #fff; position: fixed; top: 50%; left: 50%; margin-left: -350px; margin-top: -190px; z-index: 10001; border-radius: 10px; text-align: center; padding: 50px; img{ width: 80px; } .quit_title{ color: #666; font-size: 28px; margin: 45px 0px; } button { border-radius: 32px; padding:20px 0px; font-size: 26px; border-radius: 8px; width: 214px; } .quit_btn{ color: #03BA82; background: #fff; border: 1px solid #03BA82; margin-right: 32px; } .quit_close { background: linear-gradient(0deg, #03BA82, #01D695); box-shadow: 0px 3px 4px 0px rgba(1, 84, 58, 0.27); border: 1px solid #03BA82; color: #fff; } } </style> 2. Create grabDialog.js import Vue from 'vue' import Grasp from '../components/QuitDialog/QuitDialog' const PopupBox = Vue.extend(Grasp) Grasp.install = function (data) { let instance = new PopupBox({ data }).$mount() document.body.appendChild(instance.$el) Vue.nextTick(() => { instance.isQuit = true // isQuit corresponds to isQuit in the pop-up component and is used to control visibility}) } export default Grasp 3. Import in global main.js import Vue from 'vue' import Popup from './api/quitDialog' Vue.prototype.$popup = Popup.install 4. To call in the page, just call in the function methods: { graspBtn () { this.$grasp({ imgUrl: require('../../assets/home/quits.png'), // Top image. imgLoadTip: 'Image loading...', content: 'Warm Tips', title: 'Note: This learning task is not completed, do you confirm to exit', btnText: 'Cruel Exit', rightText: 'Continue to study', // Left click event leftBtn: () => { this.$store.dispatch('user/logout').then(() => { this.$signalr.LogoutPad() this.$signalr.SendMsg(2, 0, 'Exit system') this.$router.push('/login') }) }, // Right click event rightBtn: () => {} }) } } SummarizeThis is the end of this article about how to implement custom "modal pop-up window" components in Vue. For more relevant content about custom "modal pop-up window" components in Vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Seven solutions for classic distributed transactions between MySQL and Golan
Find the running container id docker ps Find the ...
The decompressed version of MYSQL is installed 1:...
Recent experience in installing mysql5.7.17 free ...
1. Search mysql in the browser to download and in...
It is very simple to install Scala environment in...
You must have saved other people’s web pages and l...
How to solve the Mysql transaction operation fail...
1. Error details Once when manually performing a ...
Table of contents 1. setTimeout() timer 2. Stop t...
I would like to share the Windows Server 2016 act...
<br />Original: Understanding Progressive En...
Table of contents DOMContentLoaded and load What ...
CenOS6.7 installs MySQL8.0.22 (recommended collec...
Table of contents Inheritance and prototype chain...
This article shares the installation and configur...