Vue實(shí)現(xiàn)通知或詳情類彈窗
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)通知或詳情類彈窗的具體代碼,供大家參考,具體內(nèi)容如下
效果如圖所示:(整體樣式模仿ant-design-vue Modal樣式,同時陰影覆蓋瀏覽器窗口,并自定義滾動條樣式)

①創(chuàng)建彈窗組件Dialog.vue:
<template>
? <div class="m-dialog-mask">
? ? <div class="m-modal">
? ? ? <div class="m-modal-content">
? ? ? ? <div @click="onClose" class="u-close">✖</div>
? ? ? ? <div class="m-modal-header">
? ? ? ? ? <div class="u-head">{{ title }}</div>
? ? ? ? </div>
? ? ? ? <div class="m-modal-body">
? ? ? ? ? <p class="u-content" v-html="content"></p>
? ? ? ? </div>
? ? ? </div>
? ? </div>
? </div>
</template>
<script>
export default {
? name: 'Dialog',
? props: {
? ? title: {
? ? ? type: String,
? ? ? default: '提示'
? ? },
? ? content: {
? ? ? type: String,
? ? ? default: ''
? ? }
? },
? methods: {
? ? onClose () {
? ? ? this.$emit('close')
? ? }
? }
}
</script>
<style lang="less>
.m-dialog-mask {
? position: fixed;
? top: 0;
? right: 0;
? bottom: 0;
? left: 0;
? width: 100%;
? height: 100%;
? z-index: 1000000;
? background: rgba(0,0,0,0.45);
? .m-modal {
? ? width: 720px;
? ? position: relative;
? ? top: calc(50% - 240px);
? ? margin: 0 auto;
? ? .m-modal-content {
? ? ? position: relative;
? ? ? background: #fff;
? ? ? border-radius: 4px;
? ? ? box-shadow: 0 4px 12px rgba(0,0,0,.1);
? ? ? .u-close {
? ? ? ? position: absolute;
? ? ? ? top: 16px;
? ? ? ? right: 24px;
? ? ? ? color: rgba(0,0,0,.45);
? ? ? ? font-size: 18px;
? ? ? ? line-height: 22px;
? ? ? ? cursor: pointer;
? ? ? ? transition: color .3s;
? ? ? ? &:hover {
? ? ? ? ? color: rgba(0,0,0,.75);
? ? ? ? }
? ? ? }
? ? ? .m-modal-header {
? ? ? ? height: 22px;
? ? ? ? padding: 16px 24px;
? ? ? ? border-radius: 4px 4px 0 0;
? ? ? ? border-bottom: 1px solid #e8e8e8;
? ? ? ? .u-head {
? ? ? ? ? margin: 0;
? ? ? ? ? color: rgba(0,0,0,.85);
? ? ? ? ? font-weight: 500;
? ? ? ? ? font-size: 16px;
? ? ? ? ? line-height: 22px;
? ? ? ? ? word-wrap: break-word;
? ? ? ? }
? ? ? }
? ? ? .m-modal-body {
? ? ? ? height: 425px;
? ? ? ? padding: 24px;
? ? ? ? font-size: 16px;
? ? ? ? line-height: 1.5;
? ? ? ? word-wrap: break-word;
? ? ? ? box-sizing: border-box;
? ? ? ? overflow: auto;
? ? ? ? .u-content {
? ? ? ? ? width: 672px;
? ? ? ? ? img { max-width: 100%; } // v-html中圖片過大時,設(shè)置其樣式最大寬度為100%
? ? ? ? }
? ? ? }
? ? ? /* 自定義滾動條樣式 */
? ? ? .m-modal-body::-webkit-scrollbar {
? ? ? ? width: 10px; /*對垂直流動條有效*/
? ? ? ? height: 10px; /*對水平流動條有效*/
? ? ? }
? ? ? /*定義滾動條的圓角、內(nèi)陰影及軌道樣式*/
? ? ? .m-modal-body::-webkit-scrollbar-track {
? ? ? ? border-radius: 5px;
? ? ? ? box-shadow: inset 0 0 6px rgba(0,0,0,.3);
? ? ? ? background: #fff;
? ? ? }
? ? ? /* 滾動條上部軌道樣式 */
? ? ? .m-modal-body::-webkit-scrollbar-track-piece:vertical:start {
? ? ? ? border-radius: 5px;
? ? ? ? background: #c3c3c3;
? ? ? }
? ? ? /*定義圓角、內(nèi)陰影及滑塊樣式*/
? ? ? .m-modal-body::-webkit-scrollbar-thumb {
? ? ? ? border-radius: 5px;
? ? ? ? box-shadow: inset 0 0 6px rgba(0,0,0,.3);
? ? ? ? background: #e8e8e8;
? ? ? ? &:hover { // 懸浮或選中時滑塊樣式
? ? ? ? ? background: #c9c9c9;
? ? ? ? }
? ? ? }
? ? }
? }
}
</style>②使用Dialog組件進(jìn)行通知,詳情類的展示:
<Dialog
? ? ? title="提示"
? ? ? :content="content"
? ? ? @close="onClose"
? ? ? v-show="showDialog"
? ? ? />
?
import Dialog from '@/components/Dialog'
components: {
? ? Dialog
}
?
data () {
? ? return {
? ? ? showDialog: false,
? ? ? content: '',
? ? }
}
methods: {
? ? onDialog (content) { // 調(diào)用Dialog彈窗展示
? ? ? this.content = content
? ? ? this.showDialog = true
? ? },
? ? onClose () { // 關(guān)閉dialog
? ? ? this.showDialog = false
? ? }
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用Vue組件實(shí)現(xiàn)一個簡單彈窗效果
- 關(guān)于vue.js彈窗組件的知識點(diǎn)總結(jié)
- vue實(shí)現(xiàn)點(diǎn)擊按鈕“查看詳情”彈窗展示詳情列表操作
- 很棒的vue彈窗組件
- vue彈窗消息組件的使用方法
- VUE實(shí)現(xiàn)可隨意拖動的彈窗組件
- Vue中關(guān)閉彈窗組件時銷毀并隱藏操作
- vue中實(shí)現(xiàn)點(diǎn)擊空白區(qū)域關(guān)閉彈窗的兩種方法
- vue的toast彈窗組件實(shí)例詳解
- vue 彈窗時 監(jiān)聽手機(jī)返回鍵關(guān)閉彈窗功能(頁面不跳轉(zhuǎn))
相關(guān)文章
ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能詳解
有時候需要用到下拉列表全選和搜索,下面這篇文章主要給大家介紹了關(guān)于ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
vue實(shí)現(xiàn)移動端輕量日期組件不依賴第三方庫的方法
這篇文章主要介紹了vue 移動端輕量日期組件不依賴第三方庫,需要的朋友可以參考下2019-04-04
vscode 配置vue+vetur+eslint+prettier自動格式化功能
這篇文章主要介紹了vscode 配置vue+vetur+eslint+prettier自動格式化功能,本文通過實(shí)例代碼圖文的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
Vue中splice()方法對數(shù)組進(jìn)行增刪改等操作的實(shí)現(xiàn)
vue中對數(shù)組的元素進(jìn)行刪除,以前一直以為這個方法是vue中特有的,后來百度之后才知道原來是js的一個寫法,下面這篇文章主要給大家介紹了關(guān)于Vue中splice()方法對數(shù)組進(jìn)行增刪改等操作的實(shí)現(xiàn)方法,需要的朋友可以參考下2023-05-05
vue前端實(shí)現(xiàn)導(dǎo)出頁面為word的兩種方法代碼
在前端開發(fā)中我們常常需要將頁面頁面為word文件,這篇文章主要給大家介紹了關(guān)于vue前端實(shí)現(xiàn)導(dǎo)出頁面為word的兩種方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04

