update $Modal with render

This commit is contained in:
梁灏 2018-06-27 09:51:38 +08:00
parent f4273043c2
commit 172e4396df
2 changed files with 56 additions and 54 deletions

View file

@ -1,43 +1,39 @@
<template>
<div>
<Button @click="instance('info')">Info</Button>
<Button @click="instance('success')">Success</Button>
<Button @click="instance('warning')">Warning</Button>
<Button @click="instance('error')">Error</Button>
<p>
Name: {{ value }}
</p>
<p>
<Button @click="handleRender">Custom content</Button>
</p>
</div>
</template>
<script>
export default {
methods: {
instance (type) {
const title = '对话框的标题';
const content = '<p>一些对话框内容</p><p>一些对话框内容</p>';
switch (type) {
case 'info':
this.$Modal.info({
title: title,
content: content
});
break;
case 'success':
this.$Modal.success({
title: title,
content: content
});
break;
case 'warning':
this.$Modal.warning({
title: title,
content: content
});
break;
case 'error':
this.$Modal.error({
title: title,
content: content
});
break;
data () {
return {
value: ''
}
},
methods: {
handleRender () {
this.$Modal.confirm({
title: '真不错呀',
render: (h) => {
return h('Input', {
props: {
value: this.value,
autofocus: true,
placeholder: 'Please enter your name...'
},
on: {
input: (val) => {
this.value = val;
}
}
})
}
})
}
}
}

View file

@ -71,6 +71,32 @@ Modal.newInstance = properties => {
]);
}
// when render with no title, hide head
let head_render;
if (this.title) {
head_render = h('div', {
attrs: {
class: `${prefixCls}-head`
}
}, [
h('div', {
class: this.iconTypeCls
}, [
h('i', {
class: this.iconNameCls
})
]),
h('div', {
attrs: {
class: `${prefixCls}-head-title`
},
domProps: {
innerHTML: this.title
}
})
]);
}
return h(Modal, {
props: Object.assign({}, _props, {
width: this.width,
@ -91,27 +117,7 @@ Modal.newInstance = properties => {
class: prefixCls
}
}, [
h('div', {
attrs: {
class: `${prefixCls}-head`
}
}, [
h('div', {
class: this.iconTypeCls
}, [
h('i', {
class: this.iconNameCls
})
]),
h('div', {
attrs: {
class: `${prefixCls}-head-title`
},
domProps: {
innerHTML: this.title
}
})
]),
head_render,
body_render,
h('div', {
attrs: {