From 131a51ec754d1fcb8765a24094d97b3e4a2b84f7 Mon Sep 17 00:00:00 2001 From: "Mr.Bai" <935196116@qq.com> Date: Tue, 22 Jun 2021 14:54:16 +0800 Subject: [PATCH] docs(message): add use not int setup demo (#215) * docs(message): use message outside of setup * docs(message): use html * Apply suggestions from code review * docs(message): put use message outside setup to Q&A section * Apply suggestions from code review Co-authored-by: tusimple Co-authored-by: 07akioni <07akioni2@gmail.com> --- src/message/demos/enUS/index.demo-entry.md | 44 ++++++++++++++++++++++ src/message/demos/zhCN/index.demo-entry.md | 44 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/message/demos/enUS/index.demo-entry.md b/src/message/demos/enUS/index.demo-entry.md index 0ec4a6b45..1b99ac06c 100644 --- a/src/message/demos/enUS/index.demo-entry.md +++ b/src/message/demos/enUS/index.demo-entry.md @@ -94,3 +94,47 @@ multiple-line | Name | Type | Description | | ------- | ---- | ----------- | | destroy | `()` | | + +## Q & A + +### Use Message Outside Setup + + + + You need to mount the return value of useMessage to the window in the top-level setup and then call it. Before calling it, you need to make sure that message has been mounted successfully. + + +```html + + + + +``` + +```html + + + + +``` + +```js +// xxx.js +export const handler = () => { + // You need to ensure that window.$message = message has been executed in setup + window.$message.success( + 'Cause you walked hand in hand With another man in my place' + ) +} +``` + + diff --git a/src/message/demos/zhCN/index.demo-entry.md b/src/message/demos/zhCN/index.demo-entry.md index fb077eabf..75d33e5c3 100644 --- a/src/message/demos/zhCN/index.demo-entry.md +++ b/src/message/demos/zhCN/index.demo-entry.md @@ -94,3 +94,47 @@ multiple-line | 名称 | 类型 | 说明 | | ------- | ---- | ---- | | destroy | `()` | | + +## Q & A + +### 在 setup 外使用 + + + + 如果你想在 setup 外使用信息,你需要在顶层 setup 中把 useMessage 返回的 message 值挂载到 window 下然后再调用,调用前需要确保 message 已经挂载成功。 + + +```html + + + + +``` + +```html + + + + +``` + +```js +// xxx.js +export const handler = () => { + // 需要确保已经在 setup 中执行了 window.$message = message + window.$message.success( + 'Cause you walked hand in hand With another man in my place' + ) +} +``` + +