message components bug fixed

message components bug fixed
This commit is contained in:
梁灏 2016-09-19 16:13:50 +08:00
parent 7c15ac9e31
commit 47e5839630
5 changed files with 25 additions and 8 deletions

View file

@ -24,6 +24,9 @@ Notification.newInstance = properties => {
notice (noticeProps) { notice (noticeProps) {
notification.add(noticeProps); notification.add(noticeProps);
}, },
remove (key) {
notification.close(key);
},
component: notification, component: notification,
destroy () { destroy () {
document.body.removeChild(div); document.body.removeChild(div);

View file

@ -63,7 +63,7 @@
}, },
methods: { methods: {
add (notice) { add (notice) {
const key = getUuid(); const key = notice.key || getUuid();
let _notice = Object.assign({ let _notice = Object.assign({
style: { style: {

View file

@ -2,11 +2,13 @@ import Notification from '../base/notification';
const prefixCls = 'ivu-message'; const prefixCls = 'ivu-message';
const iconPrefixCls = 'ivu-icon'; const iconPrefixCls = 'ivu-icon';
const prefixKey = 'ivu_message_key_';
let defaultDuration = 1.5; let defaultDuration = 1.5;
let top; let top;
let messageInstance; let messageInstance;
let key = 1;
const iconTypes = { const iconTypes = {
'info': 'information-circled', 'info': 'information-circled',
@ -42,6 +44,7 @@ function notice (content, duration = defaultDuration, type, onClose) {
let instance = getMessageInstance(); let instance = getMessageInstance();
instance.notice({ instance.notice({
key: `${prefixKey}${key}`,
duration: duration, duration: duration,
style: {}, style: {},
content: ` content: `
@ -52,6 +55,15 @@ function notice (content, duration = defaultDuration, type, onClose) {
`, `,
onClose: onClose onClose: onClose
}); });
// 用于手动消除
return (function () {
let target = key++;
return function () {
instance.remove(`${prefixKey}${target}`);
}
})();
} }
export default { export default {

View file

@ -3,7 +3,7 @@
<Button @click="success">success</Button> <Button @click="success">success</Button>
<Button @click="error">error</Button> <Button @click="error">error</Button>
<Button @click="warning">warning</Button> <Button @click="warning">warning</Button>
<Button @click="loading">loading</Button> <Button @click="loading">手动消失</Button>
</template> </template>
<script> <script>
import { Message, Button } from 'iview'; import { Message, Button } from 'iview';
@ -42,14 +42,16 @@
Message.warning('来个警告'); Message.warning('来个警告');
}, },
loading () { loading () {
Message.loading('我是loading'); const hide = Message.loading('我是loading', 0);
setTimeout(hide, 5000);
} }
}, },
ready () { ready () {
Message.config({ // Message.config({
top: 50, // top: 50,
duration: 8 // duration: 8
}); // });
} }
} }
</script> </script>

View file

@ -1,6 +1,6 @@
{ {
"name": "iview", "name": "iview",
"version": "0.0.7", "version": "0.0.8",
"title": "iView", "title": "iView",
"description": "A high quality UI components Library with Vue.js", "description": "A high quality UI components Library with Vue.js",
"homepage": "http://www.iviewui.com", "homepage": "http://www.iviewui.com",