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

How to import SQL files in Navicat Premium

I started working on my final project today, but ...

How to manage multiple projects on CentOS SVN server

One demand Generally speaking, a company has mult...

How to implement JavaScript's new operator yourself

Table of contents Constructor new Operator Implem...

Linux automatically deletes logs and example commands from n days ago

1. Delete file command: find the corresponding di...

Summary of basic knowledge points of MySql database

Table of contents Basic database operations 2) Vi...

Web page printing thin line table + page printing ultimate strategy

When I was printing for a client recently, he aske...

Linux system dual network card binding configuration implementation

System version [root@ ~]# cat /etc/redhat-release...

MYSQL local installation and problem solving

Preface This article is quite detailed and even a...

How to reduce memory usage and CPU usage of web pages

Some web pages may not look large but may be very...

Design Theory: A Method to Understand People's Hearts

<br />Once, Foyin and Mr. Dongpo were chatti...

Detailed description of mysql replace into usage

The replace statement is generally similar to ins...

A complete guide to CSS style attributes css() and width() in jQuery

Table of contents 1. Basic use of css(): 1.1 Get ...

UTF-8 and GB2312 web encoding

Recently, many students have asked me about web p...

Implementation of HTML sliding floating ball menu effect

CSS Styles html,body{ width: 100%; height: 100%; ...

How to start a Vue.js project

Table of contents 1. Node.js and Vue 2. Run the f...