Vue custom bullet box effect (confirmation box, prompt box)

Vue custom bullet box effect (confirmation box, prompt box)

This article example shares the specific code of vue custom pop-up effect for your reference. The specific content is as follows

1. Customize confirmation boxes and prompt boxes

Determine whether it is a confirmation box or a prompt box based on the type passed in

<template>
  <transition name="confirm-fade">
    <div v-if="isShowConfirm" class="my-confirm" @click.stop="clickFun('clickCancel')">
      <div class="confirm-content-wrap" @click.stop>
        <h3 class="my-confirm-title" v-show="titleText != ''">{{ titleText }}</h3>
        <p class="my-confirm-content">{{ content }}</p>
        <div class="my-operation">
          <div v-if="type==='confirm'" class="my-cancel-btn" @click="clickFun('clickCancel')">
            <p class="my-btn-text my-border-right">{{ cancelText }}</p>
          </div>
          <div class="confirm-btn" @click="clickFun('clickConfirm')">
            <p class="my-btn-text">{{ confirmText }}</p>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>
 
<script type="text/ecmascript-6">
export default {
  data () {
    return {
      isShowConfirm: false, // Used to control the display/hide of the entire window titleText: 'Operation Tips', // Prompt box title content: 'Say Something ...', // Prompt box content cancelText: 'Cancel', // Cancel button text confirmText: 'Confirm', // Confirm button text type: 'confirm', // Indicates the type of pop-up box: confirm - confirmation pop-up window (with cancel button); alert - notification pop-up box (without cancel button)
      outerData: null // Used to record data transmitted from the outside, and can also be used to monitor userBehavior and event functions to determine which event was triggered.}
  },
  methods: {
    show (content, config) {
      this.content = content || 'Say Something ...'
 
      if (Object.prototype.toString.call(config) === '[object Object]') {
        // Make sure the user passes an object this.titleText = config.titleText || ''
        this.cancelText = config.cancelText || 'Cancel'
        this.confirmText = config.confirmText || 'Confirm'
        this.type = config.type || 'confirm'
        this.outerData = config.data || null
      }
 
      this.isShowConfirm = true
    },
    hidden () {
      this.isShowConfirm = false
      this.titleText = 'Operation Tips'
      this.cancelText = 'Cancel'
      this.confirmText = 'Confirm'
      this.type = 'confirm'
      this.outerData = null
    },
    clickFun (type) {
      this.$emit('userBehavior', type, this.outerData)
      this.hidden()
    }
  }
}
</script>
 
<style scoped>
.my-confirm {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 998;
  /* This prevents the black background from appearing when the user long presses the screen, and the font scaling problem when the iPhone is horizontal and flat*/
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
 
/*Enter and exit animations*/
.confirm-fade-enter-active {
  animation: opacity 0.3s;
}
.confirm-fade-enter-active .confirm-content-wrap {
  animation: scale 0.3s;
}
.confirm-fade-leave-active {
  animation: outOpacity 0.2s;
}
 
/* Wrapping layer container style */
.confirm-content-wrap {
  position: absolute;
  top: 28%;
  left: 0;
  right: 0;
  width: 280px;
  margin: 0 auto;
  background-color: #fff;
  border-radius: 5px;
  z-index: 999;
  user-select: none;
}
 
/* Top title section */
.my-confirm-title {
  padding-top: 20px;
  text-align: center;
  font-size: 20px;
  font-weight: 500;
  color: #333;
}
 
/* Middle content part*/
.my-confirm-content {
  padding: 0 15px;
  padding-top: 20px;
  margin-bottom: 32px;
  text-align: center;
  font-size: 16px;
  color: #666;
  line-height: 1.5;
}
 
/* Bottom button style */
.my-operation {
  display: flex;
  border-top: 1px solid #eee;
}
.my-operation .my-cancel-btn, .confirm-btn {
  flex: 1;
}
.my-operation .confirm-btn {
  color: #ffb000;
}
.my-operation .my-btn-text {
  text-align: center;
  font-size: 16px;
  margin: 8px 0;
  padding: 6px 0;
}
 
/* Other decoration styles*/
.my-border-right {
  border-right: 1px solid #eee;
}
 
/* Incoming animation*/
@keyframes opacity {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@keyframes scale {
  0% {
    transform: scale(0);
  }
  60% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}
 
/* Exit animation */
@keyframes outOpacity {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
</style>

2. Call:

(1) Use of prompt box:

<DialogView ref="myDialog" @userBehavior="changeData"></DialogView>
…
//prompt box this.$refs.myDialog.show(content, {
        type: 'alert',
        confirmText: 'OK',
        cancelText: 'Cancel',
        titleText: '',
        data: null
      })

Effect:

(2) Confirmation box:

this.$refs.myDialog.show('Do you want to redeem this product?', {
            type: 'confirm',
            confirmText: 'Exchange now',
            cancelText: 'No thanks',
            titleText: '',
            data: {shop: shop, operate: 'exchange'}
          })

Effect:

When the confirmation box is pressed: changeData

<DialogView ref="myDialog" @userBehavior="changeData"></DialogView>
    …
 
    changeData (type, data) {
      console.log('changeData',data)
      if (type === 'clickConfirm') {
        if (data.operate === 'exchange') {
          // this.reduceEnergy(data.shop)
          this.exchangeCoupon(data.shop)
        } else if (data.operate === 'downLoad') {
          window.location = data.url
        } else if (data.operate === 'login') {
          this.uplusApi.upVdnModule.goToPage({url: 'mpaas://usercenter'})
          this.isLogin = false
        }
      }
},

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue tutorial toast pop-up box global call example detailed explanation
  • Toast usage in vue.js and example code using toast pop-up box
  • Vue's sample code for pop-up forms of multiple bullet boxes
  • Vue+iview writes a sample code for a pop-up box
  • How to implement a simple pop-up dialog in Vue
  • Vue implements the bullet box mask, clicks on other areas to close the bullet box, and introduces the difference between v-if and v-show
  • Vue+elementui realizes clicking on a cell in the table to trigger an event--a bullet box
  • Example code for imitating element-ui bullet box effect in vue project
  • Vue.js implements pop-up window only once
  • Solution to the scroll penetration problem caused by Vue bullet box

<<:  MySQL 8.0.11 installation and configuration method graphic tutorial MySQL 8.0 new password authentication method

>>:  CentOS 8 officially released based on Red Hat Enterprise Linux 8

Recommend

JavaScript plugin encapsulation for table switching

This article shares the encapsulation code of Jav...

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...

How are Vue components parsed and rendered?

Preface This article will explain how Vue compone...

About input file control and beautification

When uploading on some websites, after clicking t...

Three ways to draw a heart shape with CSS

Below, we introduce three ways to draw heart shap...

Facebook's nearly perfect redesign of all Internet services

<br />Original source: http://www.a-xuan.cn/...

Install Linux rhel7.3 operating system on virtual machine (specific steps)

Install virtualization software Before installing...

Understanding and application scenarios of enumeration types in TypeScript

Table of contents 1. What is 2. Use Numeric Enume...

Analyze how to automatically generate Vue component documentation

Table of contents 1. Current situation 2. Communi...

Teach you about react routing in five minutes

Table of contents What is Routing Basic use of pu...

JavaScript code to implement a simple calculator

This article example shares the specific code of ...

Hover zoom effect made with CSS3

Result:Implementation code: html <link href=&#...

Detailed explanation of Mysql transaction processing

1. MySQL transaction concept MySQL transactions a...

Why do select @@session.tx_read_only appear in DB in large quantities?

Find the problem When retrieving the top SQL stat...

Detailed tutorial on installing ElasticSearch 6.x in docker

First, pull the image (or just create a container...