From e560cef31568aec1f307e916819a4b67d9ae50e5 Mon Sep 17 00:00:00 2001 From: jiangruowei Date: Thu, 30 Mar 2017 17:26:49 +0800 Subject: [PATCH] feat: add clear method --- docs/examples-docs/toast.md | 4 ++-- packages/toast/src/toast.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/examples-docs/toast.md b/docs/examples-docs/toast.md index b0ab7a54e..844030207 100644 --- a/docs/examples-docs/toast.md +++ b/docs/examples-docs/toast.md @@ -139,10 +139,10 @@ import { Toast } from 'src/index'; export default { methods: { showToast() { - this.toast = Toast('我是提示文案,建议不超过十五字~'); + Toast('我是提示文案,建议不超过十五字~'); }, closeToast() { - this.toast.clear(); + Toast.clear(); } } }; diff --git a/packages/toast/src/toast.js b/packages/toast/src/toast.js index 9743ff5f5..eba907550 100644 --- a/packages/toast/src/toast.js +++ b/packages/toast/src/toast.js @@ -5,9 +5,8 @@ const ToastConstructor = Vue.extend(require('./toast.vue')); let instance; const getInstance = () => { - if (instance) { - instance.clear(); - } + if (instance) instance.clear(); + instance = new ToastConstructor({ el: document.createElement('div') }); @@ -70,4 +69,8 @@ Toast.fail = (options) => { }, options)); }; +Toast.clear = () => { + if (instance) instance.clear(); +} + export default Toast;