Commit dce5a3ea6b3e600a2973d0e7b4c17de14615bf68
1 parent
d519d685
update Modal
Showing
3 changed files
with
27 additions
and
2 deletions
Show diff stats
examples/routers/modal.vue
@@ -3,11 +3,32 @@ | @@ -3,11 +3,32 @@ | ||
3 | <Button @click="confirm">标准</Button> | 3 | <Button @click="confirm">标准</Button> |
4 | <Button @click="custom">自定义按钮文字</Button> | 4 | <Button @click="custom">自定义按钮文字</Button> |
5 | <Button @click="async">异步关闭</Button> | 5 | <Button @click="async">异步关闭</Button> |
6 | + <Button type="primary" @click="modal1 = true">显示对话框</Button> | ||
7 | + <Modal | ||
8 | + v-model="modal1" | ||
9 | + title="普通的Modal对话框标题" | ||
10 | + @on-ok="ok" | ||
11 | + @on-cancel="cancel"> | ||
12 | + <p>对话框内容</p> | ||
13 | + <p>对话框内容</p> | ||
14 | + <p>对话框内容</p> | ||
15 | + </Modal> | ||
6 | </div> | 16 | </div> |
7 | </template> | 17 | </template> |
8 | <script> | 18 | <script> |
9 | export default { | 19 | export default { |
20 | + data () { | ||
21 | + return { | ||
22 | + modal1: false | ||
23 | + } | ||
24 | + }, | ||
10 | methods: { | 25 | methods: { |
26 | + ok () { | ||
27 | + this.$Message.info('点击了确定'); | ||
28 | + }, | ||
29 | + cancel () { | ||
30 | + this.$Message.info('点击了取消'); | ||
31 | + }, | ||
11 | confirm () { | 32 | confirm () { |
12 | this.$Modal.confirm({ | 33 | this.$Modal.confirm({ |
13 | title: '确认对话框标题', | 34 | title: '确认对话框标题', |
src/components/modal/modal.vue
1 | <template> | 1 | <template> |
2 | - <div> | 2 | + <div v-transfer-dom> |
3 | <transition :name="transitionNames[1]"> | 3 | <transition :name="transitionNames[1]"> |
4 | <div :class="maskClasses" v-show="visible" @click="mask"></div> | 4 | <div :class="maskClasses" v-show="visible" @click="mask"></div> |
5 | </transition> | 5 | </transition> |
src/directives/transfer-dom.js
@@ -18,6 +18,7 @@ const directive = { | @@ -18,6 +18,7 @@ const directive = { | ||
18 | inserted (el, { value }, vnode) { | 18 | inserted (el, { value }, vnode) { |
19 | el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom'; | 19 | el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom'; |
20 | const parentNode = el.parentNode; | 20 | const parentNode = el.parentNode; |
21 | + if (!parentNode) return; | ||
21 | const home = document.createComment(''); | 22 | const home = document.createComment(''); |
22 | let hasMovedOut = false; | 23 | let hasMovedOut = false; |
23 | 24 | ||
@@ -38,6 +39,7 @@ const directive = { | @@ -38,6 +39,7 @@ const directive = { | ||
38 | componentUpdated (el, { value }) { | 39 | componentUpdated (el, { value }) { |
39 | // need to make sure children are done updating (vs. `update`) | 40 | // need to make sure children are done updating (vs. `update`) |
40 | const ref$1 = el.__transferDomData; | 41 | const ref$1 = el.__transferDomData; |
42 | + if (!ref$1) return; | ||
41 | // homes.get(el) | 43 | // homes.get(el) |
42 | const parentNode = ref$1.parentNode; | 44 | const parentNode = ref$1.parentNode; |
43 | const home = ref$1.home; | 45 | const home = ref$1.home; |
@@ -59,7 +61,9 @@ const directive = { | @@ -59,7 +61,9 @@ const directive = { | ||
59 | } | 61 | } |
60 | }, | 62 | }, |
61 | unbind: function unbind (el, binding) { | 63 | unbind: function unbind (el, binding) { |
62 | - el.className = el.className.replace('v-transfer-dom', '') | 64 | + el.className = el.className.replace('v-transfer-dom', ''); |
65 | + const ref$1 = el.__transferDomData; | ||
66 | + if (!ref$1) return; | ||
63 | if (el.__transferDomData.hasMovedOut === true) { | 67 | if (el.__transferDomData.hasMovedOut === true) { |
64 | el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el) | 68 | el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el) |
65 | } | 69 | } |