From e2d428d8cd7858b36904f6b4523839bc3c3b5f4d Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 21 Aug 2018 15:24:28 +0800 Subject: [PATCH] [breaking change] Notify: export default (#448) --- dist/notify/index.js | 4 +--- dist/notify/notify.js | 25 +++++++++++++++++++++++++ packages/notify/README.md | 2 +- packages/notify/index.js | 4 +--- packages/toast/README.md | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 dist/notify/notify.js diff --git a/dist/notify/index.js b/dist/notify/index.js index de20e1a2..849cbf97 100644 --- a/dist/notify/index.js +++ b/dist/notify/index.js @@ -45,7 +45,7 @@ const defaultOptions = { duration: 3000 }; -function Notify(options = {}) { +export default function Notify(options = {}) { const pages = getCurrentPages(); const ctx = pages[pages.length - 1]; @@ -65,5 +65,3 @@ function Notify(options = {}) { function parseParam(params = '') { return typeof params === 'object' ? params : { text: params }; } - -module.exports = Notify; diff --git a/dist/notify/notify.js b/dist/notify/notify.js new file mode 100644 index 00000000..dd912e26 --- /dev/null +++ b/dist/notify/notify.js @@ -0,0 +1,25 @@ +const defaultOptions = { + selector: '#van-notify', + duration: 3000 +}; + +export default function Notify(options = {}) { + const pages = getCurrentPages(); + const ctx = pages[pages.length - 1]; + + options = Object.assign({}, defaultOptions, parseParam(options)); + + const el = ctx.selectComponent(options.selector); + delete options.selector; + + if (el) { + el.setData({ + ...options + }); + el.show(); + } +} + +function parseParam(params = '') { + return typeof params === 'object' ? params : { text: params }; +} diff --git a/packages/notify/README.md b/packages/notify/README.md index f5db7961..d4e511e0 100644 --- a/packages/notify/README.md +++ b/packages/notify/README.md @@ -15,7 +15,7 @@ ### 基础用法 ```js -const Notify = require('path/to/zanui-weapp/dist/notify/index'); +import Notify from 'path/to/zanui-weapp/dist/notify/index'; Notify('通知内容') ``` diff --git a/packages/notify/index.js b/packages/notify/index.js index de20e1a2..849cbf97 100644 --- a/packages/notify/index.js +++ b/packages/notify/index.js @@ -45,7 +45,7 @@ const defaultOptions = { duration: 3000 }; -function Notify(options = {}) { +export default function Notify(options = {}) { const pages = getCurrentPages(); const ctx = pages[pages.length - 1]; @@ -65,5 +65,3 @@ function Notify(options = {}) { function parseParam(params = '') { return typeof params === 'object' ? params : { text: params }; } - -module.exports = Notify; diff --git a/packages/toast/README.md b/packages/toast/README.md index 4dad800e..f07e6d35 100644 --- a/packages/toast/README.md +++ b/packages/toast/README.md @@ -14,7 +14,7 @@ #### 文字提示 ```javascript -const Toast = require('path/to/vant-weapp/dist/toast/index'); +import Toast from 'path/to/vant-weapp/dist/toast/index'; Toast('我是提示文案,建议不超过十五字~'); ```