Skip to content

Commit 86e4734

Browse files
committed
添加modal demo
1 parent 9a2e123 commit 86e4734

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div class="">
3+
<lai-button @click.native="value = !vlaue">Toggle Modal</lai-button>
4+
<lai-modal v-model="value"></lai-modal>
5+
</div>
6+
</template>
7+
<script>
8+
import LaiModal from './modal'
9+
import LaiButton from './lai-button'
10+
export default {
11+
data () {
12+
return {
13+
value: false
14+
}
15+
},
16+
components: { LaiModal, LaiButton }
17+
}
18+
</script>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<template>
2+
<transition name="fade">
3+
<div class="modal-wrapper" v-if="isShow">
4+
<div class="modal-mask"></div>
5+
<div class="modal-main" :style="styles" v-click-outside="hide">
6+
<slot></slot>
7+
</div>
8+
</div>
9+
</transition>
10+
</template>
11+
<script>
12+
import clickOutside from '../../directives/click-outside'
13+
export default {
14+
props: {
15+
value: {
16+
type: Boolean,
17+
default: false
18+
},
19+
styles: {
20+
type: Object,
21+
default: () => {}
22+
}
23+
},
24+
data () {
25+
return {
26+
isShow: this.value
27+
}
28+
},
29+
directives: {
30+
'click-outside': clickOutside
31+
},
32+
methods: {
33+
hide () {
34+
this.isShow = false
35+
this.$emit('input', this.isShow)
36+
}
37+
},
38+
watch: {
39+
value (val) {
40+
if (this.ishow !== val) {
41+
this.isShow = val
42+
}
43+
}
44+
}
45+
}
46+
</script>
47+
48+
<style lang="less" scoped>
49+
.modal-wrapper {
50+
position: absolute;
51+
top: 0;
52+
right: 0;
53+
bottom: 0;
54+
left: 0;
55+
z-index: 99;
56+
overflow: hidden;
57+
.modal-mask {
58+
position: absolute;
59+
top: 0;
60+
right: 0;
61+
bottom: 0;
62+
left: 0;
63+
z-index: 99;
64+
background-color: rgba(0,0,0,.4);
65+
z-index: 90;
66+
}
67+
.modal-main {
68+
position: absolute;
69+
top: 0;
70+
right: 0;
71+
bottom: 0;
72+
left: 0;
73+
z-index: 99;
74+
margin: auto;
75+
width: 430px;
76+
height: 300px;
77+
background-color: #ffffff;
78+
border-radius: 4px;
79+
box-shadow: 0px 0px 6px rgba(0, 0, 0, .1);
80+
}
81+
}
82+
</style>
83+

docs/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ module.exports = {
3434
collapsable: false,
3535
children: [
3636
'/posts/components/button',
37-
'/posts/components/message'
37+
'/posts/components/message',
38+
'/posts/components/modal'
3839
]
3940
}
4041
]

docs/posts/components/modal.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Modal 模态框
2+
3+
# Alert 消息
4+
5+
##### 示例
6+
<box>
7+
<modal-demo></modal-demo>
8+
</box>
9+
10+
##### 代码
11+
```vue
12+
<lai-button @click.native="alert" type="ok">message</lai-button>
13+
...
14+
<script>
15+
let _uid = 0
16+
export default {
17+
....
18+
alert () {
19+
const types = ['success', 'info', 'warn', 'error']
20+
this.$alert({
21+
content: 'There is one message',
22+
duration: 2000,
23+
type: types[_uid%4]
24+
})
25+
}
26+
}
27+
</script>
28+
```
29+
30+
##### API
31+
<box>
32+
<mk>
33+
| 属性 | 说明 | 类型 | 默认值 |
34+
| -------- | ----------------------------------------------- | ------ | ------- |
35+
| content | 消息内容 | string ||
36+
| type | 消息类型,可选值`success` `info` `warn` `error` | string | success |
37+
| duration | 消息框存在的时间 | number | 3000 |
38+
</mk>
39+
</box>

0 commit comments

Comments
 (0)