Skip to content

Commit

Permalink
Merge pull request #12 from nihaojob/feat/content
Browse files Browse the repository at this point in the history
Feat/content
  • Loading branch information
nihaojob authored Sep 1, 2022
2 parents 381b55a + 0f72f08 commit 16556c7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ $message.destroy()
## API
### Message instance
通过直接调用以下方法来使用:
- `$message.info(msgStr, config)`
- `$message.success(msgStr, config)`
- `$message.warning(msgStr, config)`
- `$message.error(msgStr, config)`
- `$message.loading(msgStr, config)`
- `$message.info(config)`
- `$message.success(config)`
- `$message.warning(config)`
- `$message.error(config)`
- `$message.loading(config)`

参数 config 可以是字符串或对象,当为字符串时,直接显示内容,当为对象时,具体说明如下:

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ $message.destroy()
## API
### Message instance
This component can be used with the following static methods:
- `$message.info(msgStr, config)`
- `$message.success(msgStr, config)`
- `$message.warning(msgStr, config)`
- `$message.error(msgStr, config)`
- `$message.loading(msgStr, config)`
- `$message.info(config)`
- `$message.success(config)`
- `$message.warning(config)`
- `$message.error(config)`
- `$message.loading(config)`

Parameter config can be string or object. When string, the content will be directly displayed, when object, the detail usage is explained below:

Expand Down
10 changes: 9 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
$message.success('这是一条成功的提示')
$message.warning('这是一条警告的提示')
$message.error('这是一条格式错误的提示')
$message.loading('正在加载中...')</code></pre><button onclick="closeBtn()">close</button> <button onclick="closeBtnByHand()">手动close</button><pre><code class="language-js">$message.info('这是一条带关闭按钮的消息',{
$message.loading('正在加载中...')</code></pre><button onclick="objectFn()">object</button><pre><code class="language-js">$message.info({
content: '我是字符串消息'
})</code></pre><button onclick="closeBtn()">close</button> <button onclick="closeBtnByHand()">手动close</button><pre><code class="language-js">$message.info('这是一条带关闭按钮的消息',{
onClose:() => console.log('关闭'),
closable: true,
duration: 2
Expand Down Expand Up @@ -58,6 +60,12 @@
$message.loading('正在加载中...')
}

function objectFn() {
$message.info({
content: '我是字符串消息'
})
}

function closeBtnByHand() {
$message.info(
'这是一条手动带关闭按钮的消息!!!',
Expand Down
8 changes: 4 additions & 4 deletions docs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "popular-message",
"version": "1.1.8",
"version": "1.2.0",
"description": "轻量级的信息反馈组件,在顶部居中显示,并自动消失。有多种不同的提示状态可选择。",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ <h3>Example</h3>
$message.warning('这是一条警告的提示')
$message.error('这是一条格式错误的提示')
$message.loading('正在加载中...')</code></pre>


<button onclick="objectFn()">object</button>
<pre><code class="language-js">$message.info({
content: '我是字符串消息'
})</code></pre>
<button onclick="closeBtn()">close</button>
<button onclick="closeBtnByHand()">手动close</button>
<pre><code class="language-js">$message.info('这是一条带关闭按钮的消息',{
Expand Down Expand Up @@ -122,6 +128,12 @@ <h3>Example</h3>
$message.loading('正在加载中...')
}

function objectFn() {
$message.info({
content: '我是字符串消息'
})
}

function closeBtnByHand() {
$message.info(
'这是一条手动带关闭按钮的消息!!!',
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ class Message {
*/
_message(type, args) {
let options = { ...args[1] }
// 字符串模式
if (typeof args[0] === 'string') {
options.content = args[0]
}
// 对象模式
if(args.length === 1 && typeof args[0] === 'object'){
options = args[0]
console.log(options)
}
return this._render(options.content, options.duration, type, options.onClose, options.closable, options.dangerUseHtml);
}

Expand Down

0 comments on commit 16556c7

Please sign in to comment.