iVIew对话框组件封装

弹出框使用率较高,将其封装为组件

@/components/tip-modal/index.vue:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
<Modal
v-scoped
:width="width"
v-model="showTipFlag"
:title="title"
:mask-closable="false"
@on-cancel="cancel"
class-name="vertical-center-modal">
<div class="cnt">
<slot name="main-content"></slot>
<slot></slot>
</div>

<div v-if="showFooter" slot="footer">
<Button type="primary" @click.native="ok">确定</Button>
<Button @click.native="cancel">取消</Button>
</div>
<div v-else slot="footer"></div>
</Modal>
</template>

<script>
export default {
name: 'TipModal',
props: {
title: {
type: String,
default: '提示信息'
},
width: {
type: Number,
default: 535
},
showTipFlag: {
required: true,
type: Boolean
},
showFooter: {
type: Boolean,
default: true
}
},
methods: {
_updateVisible(flag) {
this.showTipFlag = flag;
this.$emit('update:showTipFlag', this.showTipFlag); //更新对话框的显示状态
},
ok() {
this.$emit('click-ok');
this._updateVisible(false);
},
cancel() {
this.$emit('click-cancel');
this._updateVisible(false);
}
}
};
</script>

<style scoped lang="less">
.cnt {
max-height: 500px;
overflow: auto;
}
.vertical-center-modal {
display: flex;
align-items: center;
justify-content: center;
.ivu-modal {
top: 0;
}
}

.ivu-modal-header-inner {
font-size: 20px;
font-weight: normal;
}

.tip-text {
font-weight: bolder;
color: #2d8cf0;
font-size: 18px;
line-height: 1.5;
}

.tip-text-assist {
color: #a6a4a6;
font-size: 15px;
}
</style>

使用:

1
2
3
<TipModal :showTipFlag.sync="addSuccessFlag" :title="'提示'" @click-ok="loadData()" :showFooter="false">
新增成功
</TipModal>