Home Web Front-end JS Tutorial Implement modal box in vue (general writing method)

Implement modal box in vue (general writing method)

Jun 04, 2018 pm 03:42 PM
Writing method modal Universal

Below I will share with you a general writing recommendation for Vue to implement modal boxes. It has a good reference value and I hope it will be helpful to everyone.

After looking at the source code of the element component, I found that all modal boxes are actually implemented in similar ways, mainly using Vue's two-way binding in componentization. Code:

<!--查看槽点对话框-->
<template lang="html">
 <transition name="el-fade-in-linear">
  <p draggable="true" @drag="mouseDrag" @dragend="mouseDragend" :style="dialogStyle" class="g-dialog-wrapper" v-show="myVisible">
   <p class="g-dialog-header">
    <p class="left">
     模态框
    </p>
    <p class="right">
     <i class="g-times-icon fa fa-times" @click="myVisible=false" aria-hidden="true"></i>
    </p>
   </p>
   <p class="g-dialog-container">
   </p>
  </p>
 </transition>
</template>
<script>
 export default {
  props: {
   visible: Boolean
  },
  created() {
  },
  data() {
   return {
    myVisible: this.visible,
  },
  computed: {},
  methods: {
  },
  components: {},
  watch: {
   myVisible: function (val) {
    this.$emit(&#39;update:visible&#39;, val)
   },
   visible: function (val) {
    this.myVisible = val
   }
  }
 }
</script>
<style lang="css" scoped>
</style>
Copy after login

The main part of the above code is the code in watch to monitor data changes and update in time. So it is very convenient to use it. After registering the component in the component:

<g-key-dialog :visible.sync="keyDialogVisible"></g-key-dialog>
Copy after login

Note: sync must be used here, otherwise it cannot be bound in two directions

above I compiled it for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Solve the problem of vue page refresh or loss of back parameters

Instances of executing functions after leaving the vue page

Usage of vue carousel plug-in vue-concise-slider

The above is the detailed content of Implement modal box in vue (general writing method). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Download Drivers for Universal PnP Monitors: 5 Ways How to Download Drivers for Universal PnP Monitors: 5 Ways Apr 21, 2023 pm 08:55 PM

If you have recently upgraded to Windows 10 or Windows 11, you may need to download a universal PnP monitor driver on your PC. Therefore, we have come up with a tutorial that will tell you more about Universal PnP Monitor and some quick ways to download and install Universal PnP Drivers on Windows. You may need to download drivers for most monitor brands, including the AcerGenericPnP monitor driver. When looking for monitor types in Device Manager or under the Monitors tab of the display adapter properties, you may notice Generic PnP Monitor. Chances are you'll find it in dual-monitor setups on both laptops and desktops. Down

Basic syntax and application of callback functions in Java Basic syntax and application of callback functions in Java Jan 30, 2024 am 08:12 AM

Introduction to the basic writing and usage of Java callback functions: In Java programming, the callback function is a common programming pattern. Through the callback function, a method can be passed as a parameter to another method, thereby achieving indirect call of the method. The use of callback functions is very common in scenarios such as event-driven, asynchronous programming and interface implementation. This article will introduce the basic writing and usage of Java callback functions, and provide specific code examples. 1. Definition of callback function A callback function is a special function that can be used as a parameter

Detailed explanation of how to write the less than sign in MyBatis Detailed explanation of how to write the less than sign in MyBatis Feb 21, 2024 pm 08:36 PM

Detailed explanation of how to write the less than sign in MyBatis MyBatis is an excellent persistence layer framework that is widely used in Java development. In the process of using MyBatis for database operations, we often use the less than sign (

How to disable universal watermark on Windows 11 PCs and laptops? How to disable universal watermark on Windows 11 PCs and laptops? Apr 21, 2023 pm 02:49 PM

Are you bothered by the annoying watermark in the lower right corner of your Windows 11 screen? You don't know how to delete it? Universal WatermarkDisabler for Windows 11 is a tool that can help remove the annoying watermark in the lower right corner of the Windows screen that interferes with wallpapers and the overall experience. Without further ado, let’s get started. 3 Solutions to Remove Watermark from Windows 11 1. Use Universal Watermark Disabler to Remove Watermark The easiest way to remove evaluation copy watermark in Windows 11 is to use Universal Watermark Disabler, which is a third-party free software

Accurate feature alignment to enhance multimodal 3D object detection: Application of GraphAlign Accurate feature alignment to enhance multimodal 3D object detection: Application of GraphAlign Oct 27, 2023 am 11:17 AM

Original title: GraphAlign: EnhancingAccurateFeatureAlignment by Graphmatching for Multi-Modal3DObjectDetection The content that needs to be rewritten is: Paper link: https://arxiv.org/pdf/2310.08261.pdf Author affiliation: Beijing Jiaotong University Hebei University of Science and Technology Tsinghua University Paper idea: LiDAR and cameras are automatic Complementary sensors for 3D object detection in driving. However, studying unnatural interactions between point clouds and images is challenging, and the key lies in how to perform feature alignment of heterogeneous modalities. Currently, many methods simply project

Learn the syntax and usage scenarios of JSP comments Learn the syntax and usage scenarios of JSP comments Jan 31, 2024 pm 03:39 PM

How to write JSP comments There are two types of JSP comments: single-line comments and multi-line comments. Single Line Comments Single line comments end with. The content of the comment is not parsed and therefore does not appear in the output. For example: Multi-line comments Multi-line comments start with /* and end with */. The content of the comment is not parsed and therefore does not appear in the output. For example: /*This is a multi-line comment*/Application scenarios of JSP comments

How to get universal controls on Mac and iPad right now with beta How to get universal controls on Mac and iPad right now with beta Jul 07, 2023 pm 09:49 PM

Requirements In addition to running macOS Monterey 12.3 or newer and iPadOS 15.4 or newer, you'll also need a newer Mac (any 2016 or newer MacBook Pro, or 2018 or newer MacBook Air, Mini, or iMac, or Mac Pro), and newer iPad (any iPad Pro, iPad Air 3rd generation or later, iPad 6th generation or later, iPad Mini 5th generation or later). Any device that wants to use Universal Control needs to be logged into the same Apple ID account that has iCloud enabled. Pass Beta now on M

Microsoft Teams is optimized for Apple Silicon as a 'Universal App' and is now available in beta Microsoft Teams is optimized for Apple Silicon as a 'Universal App' and is now available in beta Apr 15, 2023 am 08:40 AM

Microsoft Teams has finally received a version that interacts directly with ARM-based chipsets in the latest Mac PCs. A beta version of Teams optimized for Apple Silicon is available directly from Microsoft. About a year and a half ago, Apple released Mac PCs with its own proprietary chipset. Designed by Apple engineers, the M1 SoC has received a lot of praise. While the previous generation of Apple PCs featured Intel processors, these are based on ARM

See all articles