本文实例为大家分享了Vue实现通知或详情类弹窗的具体代码,供大家参考,具体内容如下 效果如图所示:(整体样式模仿ant-design-vue Modal样式,同时阴影覆盖浏览器窗口,
本文实例为大家分享了Vue实现通知或详情类弹窗的具体代码,供大家参考,具体内容如下
效果如图所示:(整体样式模仿ant-design-vue Modal样式,同时阴影覆盖浏览器窗口,并自定义滚动条样式)
①创建弹窗组件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中图片过大时,设置其样式最大宽度为100%
}
}
.m-modal-body::-WEBkit-scrollbar {
width: 10px;
height: 10px;
}
.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;
}
.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组件进行通知,详情类的展示:
<Dialog
title="提示"
:content="content"
@close="onClose"
v-show="showDialog"
/>
import Dialog from '@/components/Dialog'
components: {
Dialog
}
data () {
return {
showDialog: false,
content: '',
}
}
methods: {
onDialog (content) { // 调用Dialog弹窗展示
this.content = content
this.showDialog = true
},
onClose () { // 关闭dialog
this.showDialog = false
}
}
--结束END--
本文标题: Vue实现通知或详情类弹窗
本文链接: https://www.lsjlt.com/news/141136.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0