-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
186 lines (184 loc) · 5.34 KB
/
App.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<template>
<v-app id="app">
<v-main class="pa-5">
<v-card class="mb-5" width="500">
<v-card-title>调用示例</v-card-title>
<v-card-text>
<code>
this.$msgbox('hello world', {
center: false
})
</code>
</v-card-text>
<v-card-actions class="flex-wrap">
<v-btn
class="ml-0 mr-2 mb-2"
color="primary"
v-for="(item, index) in examples"
:key="index"
@click="msgbox(item)"
>
{{ item }}
</v-btn>
</v-card-actions>
</v-card>
<v-card class="mb-5" width="500">
<v-card-title>类型方法调用示例</v-card-title>
<v-card-text>
<code>
this.$msgbox.success('success')
</code>
</v-card-text>
<v-card-actions class="flex-wrap">
<v-btn class="ml-0 mr-2 mb-2" @click="msgType('default')">默认</v-btn>
<v-btn class="ml-0 mr-2 mb-2" color="success" @click="msgType('success')">成功</v-btn>
<v-btn class="ml-0 mr-2 mb-2" color="error" @click="msgType('error')">失败</v-btn>
<v-btn class="ml-0 mr-2 mb-2" color="warning" @click="msgType('warning')">警告</v-btn>
<v-btn class="ml-0 mr-2 mb-2" color="info" @click="msgType('info')">信息</v-btn>
<v-btn class="ml-0 mr-2 mb-2" color="primary" @click="msgType('alert')">弹出框</v-btn>
<v-btn class="ml-0 mr-2 mb-2" color="primary" @click="msgType('confirm')">确认框</v-btn>
</v-card-actions>
</v-card>
</v-main>
<messageBox v-model="visible">
111223
</messageBox>
</v-app>
</template>
<script>
import { messageBox } from '@/components/message-box'
export default {
name: 'App',
components: {
messageBox
},
data () {
return {
visible: false,
examples: [
'默认',
'带选项1',
'带选项2',
'按类型',
'使用VNode',
'关闭最后一个',
'关闭指定name',
'按钮样式',
'按钮节点',
'按钮前置后置内容',
'引入组件'
]
}
},
methods: {
msgType (type = 'default') {
if (typeof this.$msgbox[type] === 'function') {
this.$msgbox[type](type).catch(console.log)
} else if (type === 'close') {
this.$msgbox.close()
} else {
this.$msgbox(type).catch(console.log)
}
},
msgbox (mode = '默认') {
if (mode === '默认') {
// 只传入消息内容
this.$msgbox('hello world')
} else if (mode === '带选项1') {
// 传入消息内容, 选项
this.$msgbox('hello world', {
center: true
})
} else if (mode === '带选项2') {
// 只传入选项, 消息内容在选项中
this.$msgbox({
message: 'hello world',
center: true
})
} else if (mode === '按类型') {
// success error warning info
this.$msgbox.success({
message: 'hello world'
})
} else if (mode === '使用VNode') {
// content
this.$msgbox({
content: this.$createElement('div', {
style: {
color: 'red'
}
}, 'hello world')
})
} else if (mode === '关闭最后一个') {
// 默认关闭最后一个
this.$msgbox('消息1', { name: 'msg1' })
this.$msgbox('消息2', { name: 'msg2' })
setTimeout(() => {
this.$msgbox.close()
}, 2e3)
} else if (mode === '关闭指定name') {
// 传入name的消息弹框, 可以使用name来关闭
this.$msgbox('消息1', { name: 'msg1' })
this.$msgbox('消息2', { name: 'msg2' })
setTimeout(() => {
this.$msgbox.close('msg1')
}, 2e3)
} else if (mode === '按钮样式') {
this.$msgbox('按钮样式', {
cancelButtonClass: 'default',
confirmButtonClass: 'error'
})
} else if (mode === '按钮节点') {
const cancelButton = this.$createElement('v-btn', {
on: {
click: () => {
console.log(this, confirmButton)
}
}
}, '取消')
const confirmButton = this.$createElement('v-btn', {
on: {
click: () => {
console.log(this, confirmButton)
}
}
}, '确定')
this.$msgbox('按钮节点', {
confirmButton,
cancelButton
})
} else if (mode === '按钮前置后置内容') {
this.$msgbox('按钮前置后置内容', {
prepend: this.$createElement('v-btn', {
on: {
click: () => {
this.$msgbox('点击了前置按钮')
}
}
}, '前置'),
append: this.$createElement('v-btn', {
on: {
click: () => {
this.$msgbox('点击了后置按钮')
}
}
}, '后置')
})
} else if (mode === '引入组件') {
this.visible = true
}
}
},
created () {
window.app = this
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
}
</style>