首页 技术 正文
技术 2022年11月18日
0 收藏 390 点赞 2,216 浏览 2381 个字

OK,首先看看效果:

Vue 提示框组件

一、子组件(alert.vue)

<template>
<transition name="alert">
<div class="alert-all">
<div class="alert-wraper determine">
<p class="close-alert">
<!-- <i class="fa fa-times" aria-hidden="true" title="关闭" @click="close()"></i> -->
</p>
<p :class="[{fail: ifFail}, 'title']">{{title}}</p>
<div class="btn_wrapper">
<!--<div class="cancel" @click="ok(false)">取消</div>-->
<div class="ok" @click="ok(true)">确定</div>
</div>
</div>
</div>
</transition>
</template>
<script>
export default {
name: 'alert',
props: {
title: {
type: String,
default () {
return {}
}
},
type: {
type: String,
default () {
return {}
}
},
autoHide: {
type: Boolean,
default () {
return true
}
}
},
data () {
return {
ifFail: ''
}
},
methods: {
ok: function (flag) {
let data = {
show: flag,
type: this.type
}
this.$emit('okAlert', data)
}
},
mounted () {
if (this.type === 'fail') {
this.ifFail = true
} else {
this.ifFail = false
}
}
}
</script>
<style lang="less" scoped>
.alert-all{
position:fixed;
width:%;
height:%;
top:;
left:;
z-index:;
.alert-wraper{
width:400px;
height:160px;
background:#fff;
position:absolute;
top:;
left:;
right:;
bottom:;
margin:auto;
box-shadow:0px 0px 20px #ddd;
.close-alert{
height:30px;
height:30px;
width:%;
background:#4499ee;
position:relative;
z-index:;
i{
position:absolute;
right:;
width:30px;
height:30px;
font-size: 20px;
cursor:pointer;
color:#fff;
}
i::before{
position:absolute;
left:6px;
top:4px;
}
i:hover{
background:#6db2f8;
}
}
.fail{
color:red;
}
.title{
box-sizing: border-box;
padding: 10px;
width:%;
height:130px;
line-height: 25px;
font-size:14px;
font-weight: normal;
text-align:center;
display: flex;
justify-content: center;
align-items: center;
}
}
.determine{
height: 220px;
}
.btn_wrapper{
text-align: center;
}
.cancel, .ok{
display: inline-block;
width: 80px;
height: 30px;
border-radius: 20px;
border: 1px solid #4499ee;
text-align: center;
line-height: 30px;
color: #4499ee;
margin: 20px;
}
.cancel:hover, .ok:hover{
cursor: pointer;
box-shadow: 4px #4499ee;
}
}
.alert-enter-active,.alert-leave-active{
transition: all .4s
}
.alert-enter, .alert-leave-to{
opacity: ;
transform: translateY(-60px);
}
</style>

二、父组件中引用子组件(alert.vue)

<template>
<div class="container">
<alerter
v-if="alertManager.show"
:type="alertManager.type"
:title="alertManager.title">
</alerter>
</div>
</template>

三、父组件中定义变量

export default {
data () {
return {
alertManager: {
show: false,
type: '',
title: ''
}
}
}

四、父组件中写弹出框方法

 methods: {
alert (show, type, title, autoHide) {
this.alertManager = {
show: show,
type: type,
title: title
}
if (autoHide === true) {
let that = this
setTimeout(function () {
that.alertManager.show = false
}, 2000)
}
}
}

五、调用方法

that.alert(true, 'success', '提交成功', true)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,112
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,585
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922