最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue2如何設(shè)置通知提醒框

 更新時(shí)間:2026年02月24日 08:39:21   作者:月華白晝  
文章介紹了如何自定義設(shè)置通知組件的屬性,包括延時(shí)時(shí)長(zhǎng)、位置等,并提供了五種不同樣式的調(diào)用方法,最后,文章說(shuō)明了如何創(chuàng)建和引入通知框架組件

Vue2設(shè)置通知提醒框

可自定義設(shè)置以下屬性

  • 自動(dòng)關(guān)閉的延時(shí)時(shí)長(zhǎng)(duration),單位ms,默認(rèn)4500ms
  • 消息從頂部彈出時(shí),距離頂部的位置(top),單位px,默認(rèn)24px
  • 消息從底部彈出時(shí),距離底部的位置(bottom),單位px,默認(rèn)24px
  • 消息彈出位置(placement),可選:左上topLeft,右上topRight(默認(rèn)),左下bottomLeft,右下bottomRight

調(diào)用時(shí)可選以下五個(gè)方法對(duì)應(yīng)五種不同樣式

  • this.$refs.notification.open(notification) // 默認(rèn)使用
  • this.$refs.notification.info(notification) // info調(diào)用
  • this.$refs.notification.success(notification) // success調(diào)用
  • this.$refs.notification.error(notification) // error調(diào)用
  • this.$refs.notification.warn(notification) // warn調(diào)用

創(chuàng)建通知框架組件命名為Notification

<template>
  <div :class="['m-notification-wrap', placement]" :style="`top: ${placement.includes('top') ? top : ''}px; bottom: ${placement.includes('bottom') ? bottom : ''}px;`">
      <transition-group name="slide-fade" tag="div">
        <div
          class="m-notification"
          @mouseenter="onEnter(index)"
          @mouseleave="onLeave(index)"
          v-show="!hideIndex.includes(index)"
          v-for="(data, index) in notificationData"
          :key="`n${index}`">
          <svg class="u-status-svg" v-if="mode==='info'" :fill="colorStyle[mode]" viewBox="64 64 896 896" data-icon="info-circle" aria-hidden="true" focusable="false"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"></path></svg>
          <svg class="u-status-svg" v-if="mode==='success'" :fill="colorStyle[mode]" viewBox="64 64 896 896" data-icon="check-circle" aria-hidden="true" focusable="false"><path d="M699 353h-46.9c-10.2 0-19.9 4.9-25.9 13.3L469 584.3l-71.2-98.8c-6-8.3-15.6-13.3-25.9-13.3H325c-6.5 0-10.3 7.4-6.5 12.7l124.6 172.8a31.8 31.8 0 0 0 51.7 0l210.6-292c3.9-5.3.1-12.7-6.4-12.7z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg>
          <svg class="u-status-svg" v-if="mode==='warn'" :fill="colorStyle[mode]" viewBox="64 64 896 896" data-icon="exclamation-circle" aria-hidden="true" focusable="false"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M464 688a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm24-112h48c4.4 0 8-3.6 8-8V296c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8z"></path></svg>
          <svg class="u-status-svg" v-if="mode==='error'" :fill="colorStyle[mode]" viewBox="64 64 896 896" data-icon="close-circle" aria-hidden="true" focusable="false"><path d="M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4-66.1-.3c-4.4 0-8 3.5-8 8 0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 0 0-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4 66 .3c4.4 0 8-3.5 8-8 0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z"></path><path d="M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg>
          <div :class="['u-title', {'mb4': mode!=='open', 'ml48': mode!=='open'}]">{{ data.title || '--' }}</div>
          <p :class="['u-description', {'ml48': mode!=='open'}]">{{ index + data.description || '--' }}</p>
          <svg class="u-close" @click="onHideNotification(index)" viewBox="64 64 896 896" data-icon="close" aria-hidden="true" focusable="false"><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg>
        </div>
      </transition-group>
  </div>
</template>
<script>
export default {
  name: 'Notification',
  props: {
    duration: { // 自動(dòng)關(guān)閉的延時(shí)時(shí)長(zhǎng),單位ms,默認(rèn)4500ms;設(shè)置null時(shí),不自動(dòng)關(guān)閉
      type: Number,
      default: 4500
    },
    top: { // 消息從頂部彈出時(shí),距離頂部的位置,單位像素px
      type: Number,
      default: 24
    },
    bottom: { // 消息從底部彈出時(shí),距離底部的位置,單位像素
      type: Number,
      default: 24
    },
    placement: { // 消息彈出位置,可選topLeft,topRight,bottomLeft,bottomRight
      type: String,
      default: 'topRight'
    }
  },
  data () {
    return {
      colorStyle: { // 顏色主題對(duì)象
        info: '#1890FF',
        success: '#52c41a',
        error: '#f5222d',
        warn: '#faad14'
      },
      mode: 'info', // 調(diào)用方法對(duì)應(yīng)的樣式主題
      resetTimer: null,
      hideIndex: [],
      hideTimers: [],
      notificationData: []
    }
  },
  computed: {
    clear () { // 所有提示是否已經(jīng)全部變?yōu)閒alse
      return this.hideIndex.length === this.notificationData.length
    }
  },
  watch: {
    clear (to, from) { // 所有提示都消失后重置
      if (!from && to) {
        this.resetTimer = setTimeout(() => {
          this.hideIndex.splice(0)
          this.notificationData.splice(0)
        }, 500)
      }
    }
  },
  methods: {
    onEnter (index) {
      clearTimeout(this.hideTimers[index])
      this.$set(this.hideTimers, index, null)
    },
    onLeave (index) {
      if (this.duration) {
        this.$set(this.hideTimers, index, setTimeout(() => {
          this.onHideNotification(index)
        }, this.duration))
      }
    },
    show (notification) {
      clearTimeout(this.resetTimer)
      this.notificationData.push(notification)
      this.hideTimers.push(null)
      const index = this.notificationData.length - 1
      if (this.duration) {
        this.$set(this.hideTimers, index, setTimeout(() => {
          this.onHideNotification(index)
        }, this.duration))
      }
    },
    open (notification) {
      this.mode = 'open'
      this.show(notification)
    },
    info (notification) {
      this.mode = 'info'
      this.show(notification)
    },
    success (notification) {
      this.mode = 'success'
      this.show(notification)
    },
    error (notification) {
      this.mode = 'error'
      this.show(notification)
    },
    warn (notification) {
      this.mode = 'warn'
      this.show(notification)
    },
    onHideNotification (index) {
      this.hideIndex.push(index)
      this.$emit('close')
    }
  }
}
</script>
<style lang="less" scoped>
// 漸變過(guò)渡效果
.fade-enter-active, .fade-leave-active {
  transition: opacity .3s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
// 滑動(dòng)漸變過(guò)渡效果
.slide-fade-enter-active, .slide-fade-leave-active {
  transition: all .3s ease;
}
.slide-fade-enter, .slide-fade-leave-to {
  transform: translateX(408px);
  -ms-transform: translateX(408px); /* IE 9 */
  -webkit-transform: translateX(408px); /* Safari and Chrome */
  opacity: 0;
}
.topRight {
  margin-right: 24px;
  right: 0;
}
.topLeft {
  margin-left: 24px;
  left: 0;
}
.bottomRight {
  margin-right: 24px;
  right: 0;
}
.bottomLeft {
  margin-left: 24px;
  left: 0;
}
.m-notification-wrap {
  position: fixed;
  z-index: 999; // 突出顯示該層級(jí)
  width: 384px;
  color: rgba(0,0,0,.65);
  font-size: 14px;
  .m-notification {
    margin-bottom: 16px;
    padding: 16px 24px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 15%);
    line-height: 1.5;
    background: #fff;
    transition: all .3s;
    position: relative;
    .u-status-svg {
      width: 24px;
      height: 24px;
      display: inline-block;
      position: absolute;
      margin-left: 4px;
    }
    .u-title {
      padding-right: 24px;
      display: inline-block;
      margin-bottom: 8px;
      color: rgba(0,0,0,.85);
      font-size: 16px;
      line-height: 24px;
    }
    .u-description {
      font-size: 14px;
    }
    .mb4 {
      margin-bottom: 4px;
    }
    .ml48 {
      margin-left: 48px;
    }
    .u-close {
      display: inline-block;
      position: absolute;
      top: 21px;
      right: 24px;
      width: 14px;
      height: 14px;
      fill: rgba(0,0,0,.45);
      cursor: pointer;
      transition: fill .3s ease;
      &:hover {
        fill: rgba(0,0,0,.75);
      }
    }
  }
}
</style>

在要使用的頁(yè)面引入

<Notification
      ref="notification"
      placement="topRight"
      :duration="null"
      :top="30"
      @close="onClose" />
import Notification from '@/components/Notification'
components: {
    Notification
}
onShowNotification () {
      const notification = {
        title: 'Notification Title',
        description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.'
      }
      this.$refs.notification.open(notification) // 默認(rèn)使用
      // this.$refs.notification.info(notification) // info調(diào)用
      // this.$refs.notification.success(notification) // success調(diào)用
      // this.$refs.notification.error(notification) // error調(diào)用
      // this.$refs.notification.warn(notification) // warning調(diào)用
},
onClose () { // 點(diǎn)擊默認(rèn)關(guān)閉按鈕時(shí)觸發(fā)的回調(diào)函數(shù)
      console.log('關(guān)閉notification')
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • VUE中的filters過(guò)濾器使用方法

    VUE中的filters過(guò)濾器使用方法

    這篇文章主要介紹了VUE中的filters過(guò)濾器使用方法,文章主要通過(guò)描述全局過(guò)濾器、全局過(guò)濾器之單一掛載、全局過(guò)濾器之批量掛載?、組件過(guò)濾器展開(kāi)內(nèi)容,具有一定的參考價(jià)值組要的小伙伴可以參考一下
    2022-03-03
  • LRU算法在Vue內(nèi)置組件keep-alive中的使用

    LRU算法在Vue內(nèi)置組件keep-alive中的使用

    LRU算法全稱為least recently use 最近最少使用,核心思路是最近被訪問(wèn)的以后被訪問(wèn)的概率會(huì)變高,那么可以把之前沒(méi)被訪問(wèn)的進(jìn)行刪除,維持一個(gè)穩(wěn)定的最大容量值,從而不會(huì)導(dǎo)致內(nèi)存溢出。
    2021-05-05
  • Vue中SSR的作用是什么

    Vue中SSR的作用是什么

    這篇文章主要介紹了Vue中SSR的作用及使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • Vue3?vite配置css?的sourceMap及文件引用配置別名的過(guò)程

    Vue3?vite配置css?的sourceMap及文件引用配置別名的過(guò)程

    這篇文章主要介紹了Vue3 vite配置css的sourceMap,及文件引用配置別名的過(guò)程,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • VUE?html5-qrcode實(shí)現(xiàn)H5掃一掃功能實(shí)例

    VUE?html5-qrcode實(shí)現(xiàn)H5掃一掃功能實(shí)例

    這篇文章主要給大家介紹了關(guān)于VUE?html5-qrcode實(shí)現(xiàn)H5掃一掃功能的相關(guān)資料,html5-qrcode是輕量級(jí)和跨平臺(tái)的QR碼和條形碼掃碼的JS庫(kù),集成二維碼、條形碼和其他一些類型的代碼掃描功能,需要的朋友可以參考下
    2023-08-08
  • Vue2項(xiàng)目中對(duì)百度地圖的封裝使用詳解

    Vue2項(xiàng)目中對(duì)百度地圖的封裝使用詳解

    近期項(xiàng)目需求相關(guān)地圖限定使用百度地圖,功能比較簡(jiǎn)單,下面這篇文章主要給大家介紹了關(guān)于Vue2項(xiàng)目中對(duì)百度地圖的封裝使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • 基于Vue3+element-plus實(shí)現(xiàn)中英文切換功能

    基于Vue3+element-plus實(shí)現(xiàn)中英文切換功能

    在?Vue?3?項(xiàng)目中結(jié)合?vue-i18n?和?Element?Plus?實(shí)現(xiàn)中英文切換是一個(gè)常見(jiàn)的需求,下面是一個(gè)詳細(xì)的步驟指南,幫助你完成這個(gè)任務(wù),需要的朋友可以參考下
    2024-11-11
  • vue刷新頁(yè)面后params參數(shù)丟失的原因和解決方法

    vue刷新頁(yè)面后params參數(shù)丟失的原因和解決方法

    這篇文章主要給大家介紹了vue刷新頁(yè)面后params參數(shù)丟失的原因和解決方法,文中通過(guò)代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2023-12-12
  • 運(yùn)行npm?run?dev報(bào)錯(cuò)的原因及解決

    運(yùn)行npm?run?dev報(bào)錯(cuò)的原因及解決

    剛剛創(chuàng)建好vue項(xiàng)目的時(shí)候,運(yùn)行 npm run dev 會(huì)報(bào)錯(cuò),下面這篇文章主要給大家介紹了關(guān)于運(yùn)行npm?run?dev報(bào)錯(cuò)的原因及解決方法,需要的朋友可以參考下
    2022-10-10
  • Vuex和前端緩存的整合策略詳解

    Vuex和前端緩存的整合策略詳解

    這篇文章主要給大家介紹了Vuex和前端緩存的整合策略的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編一起來(lái)看看吧。
    2017-05-05

最新評(píng)論

九龙县| 木兰县| 托克逊县| 崇明县| 富裕县| 砚山县| 双流县| 珲春市| 富源县| 大厂| 邹平县| 湄潭县| 化隆| 体育| 临夏市| 密云县| 开鲁县| 尉氏县| 新丰县| 瑞安市| 杭锦后旗| 南投市| 兴义市| 昆山市| 武清区| 家居| 韩城市| 珠海市| 兴城市| 自贡市| 象山县| 合川市| 兰西县| 阳朔县| 金平| 东山县| 沈阳市| 平安县| 进贤县| 大埔县| 北辰区|