OK,首先看看效果:

一、子组件(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)

Vue 提示框组件的更多相关文章

  1. tooltip提示框组件

    Tooltip 提示框组件 可独立于其他组件通过$.fn.tooltip.defaults重写默认的defaults.当用户移动鼠标指针在某个元素上时,出现提示信息窗口来显示额外信息.提示内容可以包含 ...

  2. 第一百九十六节,jQuery EasyUI,Tooltip(提示框)组件

    jQuery EasyUI,Tooltip(提示框)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Tooltip(提示框)组件的使用方法, ...

  3. 学习EXTJS6(4)基本功能-信息提示框组件

    1.使用组件,主要配置表现形式有二种(是否可以说参数) 用逗号分隔的传统参数列表方式: <script type="text/javascript"> Ext.onRe ...

  4. 一个vue的全局提示框组件

    <template> <!-- 全局提示框 --> <div v-show="visible" class="dialog-tips dia ...

  5. jQuery Easy UI Tooptip(提示框)组件

    我们都知道DOM节点的title属性.Tooptip组件就是比較强大的title,它能够自由的设置自己的样式.位置以及有自己相关的触发事件. 演示样例: <!DOCTYPE html> & ...

  6. Tooltip(提示框)组件

    一.加载方式 //class加载方式 <a href="http://www.ycku.com" title="这是一个提示信息!" class=&quo ...

  7. vue 自定义 提示框(Toast)组件

    1.自定义 提示框 组件 src / components / Toast / index.js /** * 自定义 提示框( Toast )组件 */ var Toast = {}; var sho ...

  8. 在vue项目中添加全局提示框

    1.写一个提示框组件:msg.vue (注明:这里用两个div的原因是成功和失败的提示不能用同一个div,因为他们可能紧接着出现,所以不能从始至终只有一个提示框在工作) 2.写一个调用此组建的js : ...

  9. vue2.0 自定义 提示框(Toast)组件

    1.自定义 提示框 组件 src / components / Toast / index.js /** * 自定义 提示框( Toast )组件 */ var Toast = {}; var sho ...

随机推荐

  1. PandorBox 中安装aria2失败的解决办法

    来自:http://www.right.com.cn/forum/thread-174358-1-1.html 不论luci界面还是opkg中安装,都提示缺少依赖包uclibc,pandorabox默 ...

  2. vue-grid-layout

    vue-grid-layout    vue-grid-layout is a grid layout system, like Gridster, for Vue.js. Heavily inspi ...

  3. POJ-2752-Seek the Name-kmp的变形

    The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the l ...

  4. vue-router使用入门

    安装及基本配置 # 安装 npm install vue-router # 使用 import Vue from 'vue' import VueRouter from 'vue-router' Vu ...

  5. Java编译与反编译命令记录

    1.首先进入java文件所在的地址 1) e:/ 2) dir     (显示所有文件) 3) cd eclipse-workspace 2.使用javac命令编译Test.java文件,得到Test ...

  6. 使用CEfSharp之旅(5)CEFSharp 隔离Cookie

    原文:使用CEfSharp之旅(5)CEFSharp 隔离Cookie 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https:/ ...

  7. spring:bean的细节之三种创建Bean对象的方式

    <!--创建Bean的三种方式--><!--第一种方式,使用默认构造函数创建 在spring的配置文件中使用bean标签,配以id和class属性之后,且没有属性和标签时. 采用的就 ...

  8. java 上传MultipartFile和String post请求

    /** * POST Multipart Request * @Description: * @param requestUrl 请求url * @param requestText 请求参数 * @ ...

  9. PHPExcel SUM 返回0

    使用PHPExcel 导出Excel最后的代码是: $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007' ...

  10. 编译安装redis-3.2.9(latest stable version)

    What is the Redis? Redis is an open source (BSD licensed), in-memory data structure store, used as a ...