mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(Notify): add clear method (#2501)
This commit is contained in:
parent
cd950a65a8
commit
b5ecc922a3
@ -76,18 +76,25 @@ Notify({
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
### 方法
|
||||||
|
|
||||||
|
| 方法名 | 说明 | 参数 | 返回值 |
|
||||||
|
|------|------|------|------|
|
||||||
|
| Notify | 展示提示 | `options | message` | notify 实例 |
|
||||||
|
| Notify.clear | 关闭提示 | `options` | `void` |
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
|-----------|-----------|-----------|-------------|-------------|
|
|-----------|-----------|-----------|-------------|-------------|
|
||||||
| type | 类型,可选值为 `primary` `info` `warning` | *string* | `danger` | 1.0.0 |
|
| type | 类型,可选值为 `primary` `success` `warning` | *string* | `danger` | 1.0.0 |
|
||||||
| message | 展示文案,支持通过`\n`换行 | *string* | 1.0.0 | - |
|
| message | 展示文案,支持通过`\n`换行 | *string* | 1.0.0 | - |
|
||||||
| duration | 展示时长(ms),值为 0 时,notify 不会消失 | *number* | `3000` | - |
|
| duration | 展示时长(ms),值为 0 时,notify 不会消失 | *number* | `3000` | - |
|
||||||
| selector | 自定义节点选择器 | *string* | `van-notify` | - |
|
| selector | 自定义节点选择器 | *string* | `van-notify` | - |
|
||||||
| color | 字体颜色 | *string* | `#fff` | - |
|
| color | 字体颜色 | *string* | `#fff` | - |
|
||||||
| background | 背景颜色 | *string* | - | - |
|
| background | 背景颜色 | *string* | - | - |
|
||||||
| context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | *object* | 当前页面 | - |
|
| context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | *object* | 当前页面 | - |
|
||||||
| safe-area-inset-top | 是否留出顶部安全距离(状态栏高度) | *boolean* | `false` | - |
|
|
||||||
| onClick | 点击时的回调函数 | *Function* | - | - |
|
| onClick | 点击时的回调函数 | *Function* | - | - |
|
||||||
| onOpened | 完全展示后的回调函数 | *Function* | - | - |
|
| onOpened | 完全展示后的回调函数 | *Function* | - | - |
|
||||||
| onClose | 关闭时的回调函数 | *Function* | - | - |
|
| onClose | 关闭时的回调函数 | *Function* | - | - |
|
||||||
|
| safeAreaInsetTop | 是否留出顶部安全距离(状态栏高度) | *boolean* | `false` | - |
|
||||||
|
@ -49,7 +49,19 @@ export default function Notify(options: NotifyOptions | string) {
|
|||||||
if (notify) {
|
if (notify) {
|
||||||
notify.set(options);
|
notify.set(options);
|
||||||
notify.show();
|
notify.show();
|
||||||
} else {
|
return notify;
|
||||||
console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Notify.clear = function(options?: NotifyOptions) {
|
||||||
|
options = Object.assign({}, defaultOptions, parseOptions(options));
|
||||||
|
|
||||||
|
const context = options.context || getContext();
|
||||||
|
const notify = context.selectComponent(options.selector);
|
||||||
|
|
||||||
|
if (notify) {
|
||||||
|
notify.hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user