Skip to content

Commit 65597c7

Browse files
author
xuqingkai
committed
docs: ✏️ 常见问题增加关于useToast等hooks的答疑以及自定义编译平台的内容
1 parent ab47b68 commit 65597c7

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

docs/guide/common-problems.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,64 @@ uni-app 3.99.2023122704 将支付宝小程序的`styleIsolation`默认值设置
180180
```
181181

182182
## 为什么组件库文档中都是从`@/uni_modules/wot-design-uni`导入方法和工具类?
183+
183184
当前组件库本身的开发方式是将组件库代码放到`@/uni_modules/wot-design-uni`这个目录的,所以文档中都是从`@/uni_modules/wot-design-uni`导入方法和工具类,使用`npm`方式安装组件库的时候可以这样调整:
185+
184186
```ts
185187
// useToast、useNotify等同理
186188
import { useMessage } from '@/uni_modules/wot-design-uni'
187-
188189
```
190+
189191
替换为
190192

191193
```ts
192194
import { useMessage } from 'wot-design-uni'
195+
```
196+
197+
## uni-app 如何自定义编译平台,例如钉钉小程序?
198+
199+
可以参考`uni-app`文档中[package.json](https://uniapp.dcloud.net.cn/collocation/package.html#%E7%A4%BA%E4%BE%8B-%E9%92%89%E9%92%89%E5%B0%8F%E7%A8%8B%E5%BA%8F)章节。
200+
201+
钉钉小程序示例:
202+
```JSON
203+
{
204+
"uni-app": {
205+
"scripts": {
206+
"mp-dingtalk": {
207+
"title": "钉钉小程序",
208+
"env": {
209+
"UNI_PLATFORM": "mp-alipay"
210+
},
211+
"define": {
212+
"MP-DINGTALK": true
213+
}
214+
}
215+
}
216+
},
217+
}
218+
```
193219

220+
## 当前组件库提供的用于控制组件显示隐藏 hooks 不生效怎么办?
221+
222+
**_可以按照以下步骤进行排查_**
223+
224+
1. `uni-app`平台不支持全局挂载组件,所以`Message``Toast``Notify`等组件需在 SFC 中显式使用,例如:
225+
226+
```html
227+
<wd-toast></wd-toast>
228+
```
229+
230+
2. `useToast``useMessage``useNotify``useQueue`等 hooks 不生效,请检查是否在`setup`中调用,如果`setup`中调用,请检查当前页面是否存在多次执行`use`的场景,例如在多个组件中执行,这样会导致上一次`use`的失效。针对此场景,组件的函数式调用都支持传入`selector`参数,可以通过`selector`参数来指定组件,例如:
231+
232+
```html
233+
<wd-toast></wd-toast>
234+
<wd-toast selector="my-toast"></wd-toast>
194235
```
195236

237+
```ts
238+
const toast = useToast()
239+
const myToast = useToast({ selector: 'my-toast' })
240+
```
196241

197242
## 如何快速解决你的问题?
198243

0 commit comments

Comments
 (0)