欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue自定義彈框效果(確認(rèn)框、提示框)

 更新時(shí)間:2021年09月10日 15:28:59   作者:liuye066  
這篇文章主要為大家詳細(xì)介紹了vue自定義彈框,實(shí)現(xiàn)確認(rèn)框、提示框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue自定義彈框效果的具體代碼,供大家參考,具體內(nèi)容如下

1、自定義確認(rèn)框和提示框

根據(jù)傳入的type來判斷是確認(rèn)框或提示框

<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, // 用于控制整個(gè)窗口的顯示/隱藏
      titleText: '操作提示', // 提示框標(biāo)題
      content: 'Say Something ...', // 提示框的內(nèi)容
      cancelText: '取消', // 取消按鈕的文字
      confirmText: '確認(rèn)', // 確認(rèn)按鈕的文字
      type: 'confirm', // 表明彈框的類型:confirm - 確認(rèn)彈窗(有取消按鈕);alert - 通知彈框(沒有取消按鈕)
      outerData: null // 用于記錄外部傳進(jìn)來的數(shù)據(jù),也可以給外部監(jiān)聽userBehavior,事件的函數(shù)提供判斷到底是哪個(gè)事件觸發(fā)的
    }
  },
  methods: {
    show (content, config) {
      this.content = content || 'Say Something ...'
 
      if (Object.prototype.toString.call(config) === '[object Object]') {
        // 確保用戶傳遞的是一個(gè)對象
        this.titleText = config.titleText || ''
        this.cancelText = config.cancelText || '取消'
        this.confirmText = config.confirmText || '確認(rèn)'
        this.type = config.type || 'confirm'
        this.outerData = config.data || null
      }
 
      this.isShowConfirm = true
    },
    hidden () {
      this.isShowConfirm = false
      this.titleText = '操作提示'
      this.cancelText = '取消'
      this.confirmText = '確認(rèn)'
      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;
  /* 這里防止當(dāng)用戶長按屏幕,出現(xiàn)的黑色背景色塊,以及 iPhone 橫平時(shí)字體的縮放問題 */
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
 
/* 進(jìn)入和出去的動(dòng)畫 */
.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;
}
 
/* 包裹層容器樣式 */
.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;
}
 
/* 頂部標(biāo)題部分 */
.my-confirm-title {
  padding-top: 20px;
  text-align: center;
  font-size: 20px;
  font-weight: 500;
  color: #333;
}
 
/* 中間內(nèi)容部分 */
.my-confirm-content {
  padding: 0 15px;
  padding-top: 20px;
  margin-bottom: 32px;
  text-align: center;
  font-size: 16px;
  color: #666;
  line-height: 1.5;
}
 
/* 底部按鈕樣式 */
.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;
}
 
/* 其他修飾樣式 */
.my-border-right {
  border-right: 1px solid #eee;
}
 
/* 進(jìn)來的動(dòng)畫 */
@keyframes opacity {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@keyframes scale {
  0% {
    transform: scale(0);
  }
  60% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}
 
/* 出去的動(dòng)畫 */
@keyframes outOpacity {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
</style>

2、調(diào)用:

(1)提示框的使用:

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

效果:

(2)確認(rèn)框:

this.$refs.myDialog.show('要兌換這個(gè)商品么?', {
            type: 'confirm',
            confirmText: '立即兌換',
            cancelText: '不用了',
            titleText: '',
            data: {shop: shop, operate: 'exchange'}
          })

效果:

當(dāng)為確認(rèn)框時(shí)的按鍵處理: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
        }
      }
},

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 在vue中使用iframe解決視頻資源的防盜鏈

    在vue中使用iframe解決視頻資源的防盜鏈

    我們的vue2.0項(xiàng)目當(dāng)中,存儲(chǔ)了許多圖片和視頻資源,所以我們需要增加防盜鏈設(shè)置,但是這樣一來,當(dāng)我們將其他網(wǎng)站上的視頻資源,想入到我們的環(huán)境當(dāng)中的時(shí)候,會(huì)報(bào)錯(cuò),所以本文給大家介紹了在vue中使用iframe解決視頻資源的防盜鏈,需要的朋友可以參考下
    2023-12-12
  • Vue加載中動(dòng)畫組件使用方法詳解

    Vue加載中動(dòng)畫組件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Vue加載中動(dòng)畫組件使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 手把手教你在vue中使用three.js

    手把手教你在vue中使用three.js

    最近在vue3項(xiàng)目中通過three.js實(shí)現(xiàn)了實(shí)際的三維效果demo,下面這篇文章主要給大家介紹了關(guān)于在vue中使用three.js的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • vue2.0+vue-router構(gòu)建一個(gè)簡單的列表頁的示例代碼

    vue2.0+vue-router構(gòu)建一個(gè)簡單的列表頁的示例代碼

    這篇文章主要介紹了vue2.0+vue-router構(gòu)建一個(gè)簡單的列表頁的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • vue3利用keepAlive緩存頁面實(shí)例詳解

    vue3利用keepAlive緩存頁面實(shí)例詳解

    <keep-alive> 是一個(gè)抽象組件,它自身不會(huì)渲染一個(gè)DOM元素,也不會(huì)出現(xiàn)在組件的父組件鏈中,下面這篇文章主要給大家介紹了關(guān)于vue3利用keepAlive緩存頁面的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • vue.js實(shí)現(xiàn)一個(gè)瀑布流的組件

    vue.js實(shí)現(xiàn)一個(gè)瀑布流的組件

    這篇文章主要為大家介紹了vue.js實(shí)現(xiàn)一個(gè)瀑布流的組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • 老生常談vue的生命周期

    老生常談vue的生命周期

    這篇文章主要為大家詳細(xì)介紹了vue的生命周期,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02
  • vue實(shí)現(xiàn)3D環(huán)形圖效果

    vue實(shí)現(xiàn)3D環(huán)形圖效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)3D環(huán)形圖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • vue+elementui+vuex+sessionStorage實(shí)現(xiàn)歷史標(biāo)簽菜單的示例代碼

    vue+elementui+vuex+sessionStorage實(shí)現(xiàn)歷史標(biāo)簽菜單的示例代碼

    本文主要介紹了vue+elementui+vuex+sessionStorage實(shí)現(xiàn)歷史標(biāo)簽菜單的示例代碼,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 淺談Vue3.0新版API之composition-api入坑指南

    淺談Vue3.0新版API之composition-api入坑指南

    這篇文章主要介紹了Vue3.0新版API之composition-api入坑指南,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04

最新評論