Closed ameegle closed 1 year ago
@ameegle 可以开启toast的多例模式
import React from 'react'
import { Cell, Toast, Switch } from 'react-vant'
type ToastReturnType = {
clear: () => void;
}
Toast.allowMultiple(true)
let t1: ToastReturnType;
let t2: ToastReturnType;
export default () => {
return (
<>
<Cell
title='第一个Toast'
isLink
onClick={() =>
t1 = Toast({
message: '第一个Toast',
duration: 0,
position: 'top'
})
}
/>
<Cell
title='第二个Toast'
isLink
onClick={() =>
t2= Toast({
message: '第二个Toast',
duration: 0,
position: 'bottom'
})
}
/>
<Cell
title='清除第一个Toast'
isLink
onClick={() =>
t1.clear()
}
/>
<Cell
title='清楚第二个Toast'
isLink
onClick={() =>
t2.clear()
}
/>
</>
)
}
What is the new or updated feature that you are suggesting?
目前
toast
关闭通过实例或全局方法clear
完成, 在实际中遇到以下情况:使用
Toast.clear()
方法, 会把刚刚创建的Toast.info
组件给清除了 所以有个想法Toast.clear()
替换成Toast.clear(type?:ToastType)
, 根据传入的type来匹配移除.Why should this feature be included?
Toast
中的'loading' | 'success' | 'fail' | 'info'
都返回一个ToastReturnType
, 里面包含一个clear
方法, 再加上全局的clear
方法, 总体上有点混乱. 可不可以归总成一个方法挂载到Toast
上, 如:Toast.clear(type?:ToastType)