|
| 1 | +# useMessage |
| 2 | + |
| 3 | +用于便捷地调用 MessageBox 弹框组件。 |
| 4 | + |
| 5 | +## Alert 弹框 |
| 6 | + |
| 7 | +alert 弹框只有确定按钮,用于强提醒。 |
| 8 | + |
| 9 | +```html |
| 10 | +<wd-message-box></wd-message-box> |
| 11 | +<wd-button @click="alert">alert</wd-button> |
| 12 | +``` |
| 13 | + |
| 14 | +```ts |
| 15 | +import { useMessage } from '@/uni_modules/wot-design-uni' |
| 16 | +const message = useMessage() |
| 17 | + |
| 18 | +function alert() { |
| 19 | + message.alert('操作成功') |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +## Confirm 弹框 |
| 24 | + |
| 25 | +用于提示用户操作。 |
| 26 | + |
| 27 | +```html |
| 28 | +<wd-message-box /> |
| 29 | +<wd-button @click="confirm">confirm</wd-button> |
| 30 | +``` |
| 31 | + |
| 32 | +```ts |
| 33 | +import { useMessage } from '@/uni_modules/wot-design-uni' |
| 34 | +const message = useMessage() |
| 35 | + |
| 36 | +function confirm() { |
| 37 | + message |
| 38 | + .confirm({ |
| 39 | + msg: '提示文案', |
| 40 | + title: '标题' |
| 41 | + }) |
| 42 | + .then(() => { |
| 43 | + console.log('点击了确定按钮') |
| 44 | + }) |
| 45 | + .catch(() => { |
| 46 | + console.log('点击了取消按钮') |
| 47 | + }) |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +## Prompt 弹框 |
| 52 | + |
| 53 | +prompt 会展示一个输入框,并可以进行输入校验。 |
| 54 | + |
| 55 | +```html |
| 56 | +<wd-message-box /> |
| 57 | +<wd-button @click="prompt">prompt</wd-button> |
| 58 | +``` |
| 59 | + |
| 60 | +```ts |
| 61 | +import { useMessage } from '@/uni_modules/wot-design-uni' |
| 62 | +const message = useMessage() |
| 63 | + |
| 64 | +function prompt() { |
| 65 | + message |
| 66 | + .prompt({ |
| 67 | + title: '请输入邮箱', |
| 68 | + inputPattern: /.+@.+\..+/i, |
| 69 | + inputError: '邮箱格式不正确' |
| 70 | + }) |
| 71 | + .then((resp) => { |
| 72 | + console.log(resp) |
| 73 | + }) |
| 74 | + .catch((error) => { |
| 75 | + console.log(error) |
| 76 | + }) |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## API |
| 81 | + |
| 82 | +### Methods |
| 83 | + |
| 84 | +| 方法名称 | 说明 | 参数 | |
| 85 | +|--------|----------------|---------| |
| 86 | +| show | 展示弹框 | options | |
| 87 | +| alert | 展示 Alert 弹框 | options | |
| 88 | +| confirm| 展示 Confirm 弹框| options | |
| 89 | +| prompt | 展示 Prompt 弹框| options | |
| 90 | +| close | 关闭弹框 | - | |
| 91 | + |
| 92 | +### Options |
| 93 | + |
| 94 | +| 参数 | 说明 | 类型 | 可选值 | 默认值 | |
| 95 | +|-----|------|------|--------|--------| |
| 96 | +| title | 标题 | string | - | - | |
| 97 | +| msg | 消息文案 | string | - | - | |
| 98 | +| type | 弹框类型 | string | alert / confirm / prompt | alert | |
| 99 | +| closeOnClickModal | 是否支持点击蒙层进行关闭 | boolean | - | true | |
| 100 | +| inputType | 当type为prompt时,输入框类型 | string | - | text | |
| 101 | +| inputValue | 当type为prompt时,输入框初始值 | string / number | - | - | |
| 102 | +| inputPlaceholder | 当type为prompt时,输入框placeholder | string | - | 请输入内容 | |
| 103 | +| inputPattern | 当type为prompt时,输入框正则校验 | RegExp | - | - | |
| 104 | +| inputValidate | 当type为prompt时,输入框校验函数 | function | - | - | |
| 105 | +| inputError | 当type为prompt时,输入框检验不通过时的错误提示文案 | string | - | 输入的数据不合法 | |
| 106 | +| confirmButtonText | 确定按钮文案 | string | - | 确定 | |
| 107 | +| cancelButtonText | 取消按钮文案 | string | - | 取消 | |
| 108 | +| zIndex | 弹窗层级 | number | - | 99 | |
| 109 | +| selector | 指定唯一标识 | string | - | '' | |
0 commit comments