亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue通知提醒框(Notification)圖文詳解

 更新時(shí)間:2022年11月25日 09:20:06   作者:theMuseCatcher  
最近有個(gè)項(xiàng)目需求就是在客戶端的右上角要實(shí)時(shí)展示提醒消息,下面這篇文章主要給大家介紹了關(guān)于Vue通知提醒框(Notification)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

相關(guān)組件或插件運(yùn)行時(shí)的項(xiàng)目依賴版本信息

項(xiàng)目運(yùn)行時(shí)依賴:vue@^2.6.12  vue-router@3.6.4

項(xiàng)目開(kāi)發(fā)時(shí)依賴:less@^4.1.3   less-loader@^5.0.0  vue-template-compiler@^2.6.12

"dependencies": {
    "axios": "^0.27.2",
    "core-js": "^3.6.5",
    "echarts": "^5.3.3",
    "swiper": "5.4.5",
    "vue": "^2.6.12",
    "vue-amazing-selector": "^0.2.6",
    "vue-lazyload": "1.3.3",
    "vue-router": "3.6.4",
    "vuedraggable": "^2.24.3"
},
"devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.15",
    "@vue/cli-plugin-eslint": "~4.5.15",
    "@vue/cli-service": "~4.5.15",
    "@vue/eslint-config-standard": "^5.1.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^6.0.1",
    "eslint-plugin-standard": "^5.0.0",
    "eslint-plugin-vue": "^6.2.2",
    "less": "^4.1.3",
    "less-loader": "^5.0.0",
    "vue-template-compiler": "^2.6.12",
    "webpack-bundle-analyzer": "^4.6.1",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "compression-webpack-plugin": "^6.0.2"
}

可自定義設(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.warning(notification) // warning調(diào)用

五種樣式效果如下圖:

open()調(diào)用:

info()調(diào)用:

 success()調(diào)用:

error()調(diào)用:

warning()調(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 name="slide-fade" v-for="(data, index) in notificationData" :key="index">
        <div class="m-notification" v-if="showNotification[index]">
          <div class="m-notification-content">
            <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==='warning'" :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'}]">{{ data.description || '--' }}</p>
          </div>
          <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>
  </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',
        warning: '#faad14'
      },
      mode: 'info', // 調(diào)用方法對(duì)應(yīng)的樣式主題
      resetTimer: null,
      showNotification: [],
      hideTimers: [],
      notificationData: []
    }
  },
  computed: {
    clear () { // 所有提示是否已經(jīng)全部變?yōu)閒alse
      return this.showNotification.every(item => !item)
    }
  },
  watch: {
    clear (to, from) { // 所有提示都消失后重置
      if (!from && to) {
        this.resetTimer = setTimeout(() => {
          this.notificationData.splice(0)
          this.showNotification.splice(0)
        }, 500)
      }
    }
  },
  methods: {
    onEnter (index) {
      clearTimeout(this.hideTimers[index])
    },
    onLeave (index) {
      if (this.duration) {
        this.onHideNotification(index)
      }
    },
    show (notification) {
      clearTimeout(this.resetTimer)
      this.notificationData.push(notification)
      const index = this.notificationData.length - 1
      console.log('index:', index)
      this.$nextTick(() => { // 待異步更新隊(duì)列之后顯示提示框,否則過(guò)渡效果會(huì)異常
        this.$set(this.showNotification, index, true)
        if (this.duration) {
          this.onHideNotification(index)
        }
      })
    },
    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)
    },
    warning (notification) {
      this.mode = 'warning'
      this.show(notification)
    },
    onHideNotification (index) {
      if (this.duration) {
        this.hideTimers[index] = setTimeout(() => {
          this.$set(this.showNotification, index, false)
          this.$emit('close')
        }, this.duration)
      } else {
        this.$set(this.showNotification, index, false)
        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 .5s 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 {
    position: relative;
    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;
    .m-notification-content {
      .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: 16px;
      right: 22px;
      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.warning(notification) // warning調(diào)用
},
onClose () { // 點(diǎn)擊默認(rèn)關(guān)閉按鈕時(shí)觸發(fā)的回調(diào)函數(shù)
      console.log('關(guān)閉notification')
}

總結(jié)

到此這篇關(guān)于Vue通知提醒框(Notification)的文章就介紹到這了,更多相關(guān)Vue通知提醒框Notification內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

  • vue-cli axios請(qǐng)求方式及跨域處理問(wèn)題

    vue-cli axios請(qǐng)求方式及跨域處理問(wèn)題

    這篇文章主要介紹了vue-cli axios請(qǐng)求方式及跨域處理問(wèn)題,文中還給大家提到了vue中axios解決跨域問(wèn)題和攔截器使用,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2018-03-03
  • 基于Ant-design-vue的Modal彈窗 封裝 命令式與Hooks用法

    基于Ant-design-vue的Modal彈窗 封裝 命令式與Hooks用法

    這篇文章主要給大家介紹了基于Ant-design-vue的Modal彈窗封裝命令式與Hooks用法,文中有詳細(xì)的代碼示例,具有一定的參考價(jià)值,感興趣的同學(xué)可以借鑒閱讀
    2023-06-06
  • 一個(gè)Vue視頻媒體多段裁剪組件的實(shí)現(xiàn)示例

    一個(gè)Vue視頻媒體多段裁剪組件的實(shí)現(xiàn)示例

    這篇文章主要介紹了一個(gè)Vue媒體多段裁剪組件的實(shí)現(xiàn)示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • vue項(xiàng)目里面引用svg文件并給svg里面的元素賦值

    vue項(xiàng)目里面引用svg文件并給svg里面的元素賦值

    這篇文章主要介紹了vue項(xiàng)目里面引用svg文件并給svg里面的元素賦值,本文分步驟通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • vue3下watch的使用方法示例

    vue3下watch的使用方法示例

    vue3中的watch是一個(gè)組合式的API使用時(shí)需要引入,下面這篇文章主要給大家介紹了關(guān)于vue3下watch使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • vuex數(shù)據(jù)持久化的兩種實(shí)現(xiàn)方案

    vuex數(shù)據(jù)持久化的兩種實(shí)現(xiàn)方案

    在vuex的時(shí)候刷新以后里面存儲(chǔ)的state就會(huì)被瀏覽器釋放掉,因?yàn)槲覀兊膕tate都是存儲(chǔ)在內(nèi)存中的,所以一刷新頁(yè)面就會(huì)把state中的數(shù)據(jù)重置,這就涉及到vue數(shù)據(jù)持久化的問(wèn)題,這篇文章主要給大家介紹了關(guān)于vuex數(shù)據(jù)持久化的兩種實(shí)現(xiàn)方案,需要的朋友可以參考下
    2021-07-07
  • vue?遮罩和ref的使用setup版和非setup版

    vue?遮罩和ref的使用setup版和非setup版

    這篇文章主要介紹了vue?遮罩和ref的使用,setup版和非setup版,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • vue3?實(shí)現(xiàn)關(guān)于?el-table?表格組件的封裝及調(diào)用方法

    vue3?實(shí)現(xiàn)關(guān)于?el-table?表格組件的封裝及調(diào)用方法

    這篇文章主要介紹了vue3?實(shí)現(xiàn)關(guān)于?el-table?表格組件的封裝及調(diào)用方法,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-06-06
  • vue-video-player 解決微信自動(dòng)全屏播放問(wèn)題(橫豎屏導(dǎo)致樣式錯(cuò)亂問(wèn)題)

    vue-video-player 解決微信自動(dòng)全屏播放問(wèn)題(橫豎屏導(dǎo)致樣式錯(cuò)亂問(wèn)題)

    這篇文章主要介紹了vue-video-player 解決微信自動(dòng)全屏播放問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • 在vue中使用iframe解決視頻資源的防盜鏈

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

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

最新評(píng)論