Skip to content

useToast

Used to conveniently call the Toast light prompt component.

Basic Usage

Need to import wd-toast component in the page as the mount point.

html
<wd-toast />
<wd-button @click="showToast">toast</wd-button>
ts
import { useToast } from '@/uni_modules/wot-ui'

const toast = useToast()

function showToast() {
  toast.show('Prompt message')
}

Success, Error, Warning, Normal

ts
toast.show('Prompt message')
toast.success('Operation successful')
toast.error('Mobile verification code input error, please re-enter')
toast.warning('Prompt message')
toast.info('Normal prompt message')

Using Icons

You can use iconClass to specify icons, combined with classPrefix to use custom icons, see Icon Custom Icons.

ts
// Use component library internal icons
toast.show({
  iconClass: 'star',
  msg: 'Using component library internal icons'
})
ts
// Use custom icons
toast.show({
  iconClass: 'kehuishouwu',
  classPrefix: 'fish',
  msg: 'Using custom icons'
})

Loading Prompt

After loading is enabled, users need to manually close it. You can call close to close it, or call toast again, because only one toast exists at a time, and the new toast will automatically replace the old one.

ts
toast.loading('Loading...')

Modify loading indicator type:

ts
toast.loading({
  loadingType: 'ring',
  msg: 'Loading...'
})

Manually close loading:

ts
toast.close()

API

Methods

Method NameDescriptionParameters
showShow promptoptions
successSuccess promptoptions
errorError promptoptions
infoNormal promptoptions
warningWarning promptoptions
loadingLoading promptoptions
closeManually close message prompt box-

Options

ParameterDescriptionTypeOptional ValuesDefault Value
msgMessage contentstring-''
durationDuration in ms, 0 means no auto-closenumber-2000
directionLayout directionstringvertical / horizontalhorizontal
iconNameIcon typestringsuccess / error / warning''
iconSizeLeft icon sizenumber--
iconClassCustom icon class namestring-''
classPrefixClass name prefixstring-'wd-icon'
positionPosition of prompt message boxstringtop / middle / bottommiddle-top
zIndextoast z-indexnumber-100
loadingTypeLoading icon typestringringoutline
loadingColorLoading icon colorstring-#4D80F0
selectorSpecify unique identifierstring-''
coverWhether there is a transparent coverboolean-false
openedCallback function after fully displayedFunction--
closedCallback function after fully closedFunction--

Released under the MIT License.

Released under the MIT License.