Skip to content

useToast ​

Used for conveniently calling the Toast lightweight prompt component.

Basic Usage ​

You need to import the wd-toast component in the page as a mounting point.

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

const toast = useToast()

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

Success, Error, Warning, Regular ​

ts
toast.show('Prompt message')
toast.success('Operation successful')
toast.error('Invalid phone verification code, please re-enter')
toast.warning('Warning message')
toast.info('Regular prompt message')

Using Icons ​

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

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

Loading Prompt ​

When loading is enabled, it needs to be closed manually by the user. You can call close, or call another toast prompt, because only one toast will exist, and a 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
infoRegular promptoptions
warningWarning promptoptions
loadingLoading promptoptions
closeManually close message prompt box-

Options ​

ParameterDescriptionTypeAccepted ValuesDefault
msgMessage contentstring-''
durationDuration in ms, 0 means no automatic closingnumber-2000
directionLayout directionstringvertical / horizontalhorizontal
iconNameIcon typestringsuccess / error / warning''
iconSizeLeft icon sizenumber--
iconClassCustom icon class namestring-''
classPrefixClass name prefixstring-'wd-icon'
positionPrompt box positionstringtop / middle / bottommiddle-top
zIndexToast z-indexnumber-100
loadingTypeLoading icon typestringringoutline
loadingColorLoading icon colorstring-#4D80F0
selectorUnique identifierstring-''
coverWhether there is a transparent maskboolean-false
openedCallback function after fully displayedFunction--
closedCallback function after fully closedFunction--

Released under the MIT License.

Released under the MIT License.